php-网上下载

2023-03-03 19:22:57 浏览数 (1)

浏览量 2

代码语言:javascript复制
set_time_limit(0);
// URL 
$url = ‘http://somsite.com/some_video.flv‘;
$pi = pathinfo($url);
$ext = $pi[‘extension‘];
$name = $pi[‘filename‘];
$ch = curl_init();
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);
// 抓取网址并将其传递给浏览器
$opt = curl_exec($ch);
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

0 人点赞