我有一個文件輸出的問題,它真的很小,像4kb左右,文件說「400 - 錯誤的請求」。php下載文件在下載管理器
來自源代碼,正確的大小是28.2mb。
$url = 'http://mozilla.isu.net.sa/firefox/releases/7.0.1/mac/en-US/Firefox%207.0.1.dmg';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 360);
curl_setopt($curl, CURLOPT_COOKIEJAR, 'temp/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEFILE, 'temp/cookie.txt');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
$curl_out = curl_exec($curl);
curl_close($curl);
$filename = explode('/', $url);
$filename = $filename[count($filename)-1];
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="'.$filename.'"');
print($curl_out);
如果它不能處理更大的文件,另一種方法:我想從PHP和餅乾下載着源鏈接...然後怎麼樣?
嘗試vardumping curl_out並在文件檢索中查找錯誤 – jancha
u mean var_dump($ curl_out)? – user453089
@jancha我試着'echo var_dump($ curl_out);'輸出:'
串(349) 「<! - ?XML版本=」 1.0" 編碼= 「ISO-8859-1」? - >400 - 錯誤要求
「 ' – user453089