我必須從網絡源下載與數據相關的pdf文件。我知道文件的完整路徑。我已經嘗試過使用curl,但花了很長時間並寫了一個0字節的文件。如何使用php下載文件,提供的路徑已知
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata = curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
fclose($fp);
請發表您的代碼。 – Shoban 2012-03-30 04:35:31
發佈您的代碼。 – Nilpo 2012-03-30 04:36:12
[你有什麼試過](http://mattgemmell.com/2008/12/08/what-have-you-tried/)? – ghoti 2012-03-30 04:36:41