使用PHP

时间:2017-11-22 04:41:59

标签: php curl

我正在尝试使用curl函数下载带有URL的视频,我在执行此操作时收到错误。

  

错误:无法打开流:未知错误警告:curl_setopt():   提供的参数不是有效的文件句柄资源错误: -   请求的URL返回错误:403 Forbidden

$file_url = "https://r7---sn-5hne6nse.googlevideo.com/videoplayback?nh=IgpwcjA0LmFtczE1KgkxMjcuMC4wLjE&dur=9506.899&signature=7AE59A98DC631F320F23928EB823EB8A42AFA3ED.DA59E710F432FCC58F083D8AC7D52F3A592F809A&initcwndbps=2113750&ei=aAUVWszAD5HW1wLBkrjwDw&lmt=1471404907996618&sparams=dur%2Cei%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cnh%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&expire=1511348680&ms=au&id=o-ANUZv3t4OvJIXUC1ZiLxywIPvA9gtJOCH1fO5Yv_NaF6&mv=m&mt=1511326928&mn=sn-5hne6nse&pl=22&source=youtube&mm=31&requiressl=yes&ip=37.58.82.168&mime=video%2Fmp4&itag=22&ipbits=0&ratebypass=yes&key=yt6&title=PMI+-+ACP+Tutorial+Part+1+%7C+PMI+ACP+Exam+Tutorial+for+Beginners-1+%7C+PMI+Agile+Certification";
$upload_dir = realpath('public/uploads/contents/download/');
$name       = uniqid();
$save_to    = $upload_dir.'/'.$name.'.mp4';
$downloaded_file = fopen($save_to, 'w');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FILE, $downloaded_file);
$page = curl_exec($ch);
if (!$page) {
    echo "Error :- ".curl_error($ch);
}
curl_close($ch);

我可以使用此代码下载PDF文件,但不适用于此视频下载。任何建议?

0 个答案:

没有答案