set_time_limit(0); // supports all file types // url here: $url = 'http://somsite.com/some_video.flv'; $pi = pathinfo($url); $ext = $pi['extension']; $name = $pi['filename']; // create a new curl resource $ch = curl_init(); // set url and other appropriate options curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_binarytransfer, true); curl_setopt($ch, curlopt_autoreferer, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_returntransfer, true); // grab url and pass it to the browser $opt = curl_exec($ch); // close curl resource, and free up system resources curl_close($ch); $savefile = $name.'.'.$ext; if(preg_match(/[^0-9a-z._-]/i, $savefile)) $savefile = md5(microtime(true)).'.'.$ext; $handle = fopen($savefile, 'wb'); fwrite($handle, $opt); fclose($handle);
复制代码
php