cURL下载文件问题 [英] cURL download file issues
本文介绍了cURL下载文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从Google驱动器下载文件,但当我播放脚本时,它会出现以下错误:
I am trying to download a file from Google drive, but when I play the script, it gives me following error:
Moved Temporarily
The document has moved here.
我的代码如下:
$source = "https://docs.google.com/uc?id=0B8tmy5YxFFGhM0szSUZWVl9qQWc&export=download";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
echo $data = curl_exec($ch);
echo $error = curl_error($ch);
//print_r($ch);
$destination = "data.csv";
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
curl_close ($ch);
推荐答案
看起来您正在接收重定向。您可以要求curl遵循以下重定向:
Looks like you're receiving a redirect. You can ask curl to follow redirects with the following:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
这篇关于cURL下载文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文