php-网上下载

2021-11-27 177 0

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);

相关文章

Linux-如何升级php的版本
WordPress-更换链接格式之后报404错误
Linux-使用Remi源安装最新版PHP
PHP-WordPress连接数据库失败问题
php-网络安全实验室脚本关快速口算题
php-从网页中提取关键字

发布评论