我想从异地服务器下载文件。如果出现这种情况,我确实同意这样做:) 我拥有的是一个 cURL 脚本,它可以获取标题和文件名,但无论出于何种原因,我都无法将文件 dl 到我的服务器。
$downloadvUrl="$videos";
$file = "downloads";
$fileName=$downloadvUrl;
$header = array(
"Accept-Encoding: gzip,deflate",
"Accept-Charset: utf-8;q=0.7,*;q=0.7",
"Connection: close"
);
$file2 = dirname(__file__).'/'.videos.'.m4v';
$curlObj=curl_init();
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlObj, CURLOPT_HEADER, false);
curl_setopt($curlObj, CURLOPT_USERAGENT, $useragent);
curl_setopt($curlObj, CURLOPT_CONNECTTIMEOUT, 999);
curl_setopt($curlObj, CURLOPT_TIMEOUT, 9999);
curl_setopt($curlObj, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curlObj, CURLOPT_URL, $downloadvUrl);
$response = curl_exec($curlObj);
$return = false;
if(!curl_errno($curlObj)) {
file_put_contents($file2, $response);
}