從URL下載文件到服務器嗯,這個看起來很簡單,而且確實如此。要將文件下載到服務器,所需做的就是:file_put_contents("Tmpfile.zip", file_get_contents("http://someurl/file.zip"));只有一個問題。如果你有一個很大的文件,比如100 MB。然后,您將耗盡內(nèi)存,無法下載該文件。我想要的是一種在下載文件時將文件寫入磁盤的方法。這樣,我可以下載更大的文件,而不會遇到內(nèi)存問題。
3 回答

白衣染霜花
TA貢獻1796條經(jīng)驗 獲得超10個贊
private function downloadFile($url, $path){ $newfname = $path; $file = fopen ($url, 'rb'); if ($file) { $newf = fopen ($newfname, 'wb'); if ($newf) { while(!feof($file)) { fwrite($newf, fread($file, 1024 * 8), 1024 * 8); } } } if ($file) { fclose($file); } if ($newf) { fclose($newf); }}
- 3 回答
- 0 關注
- 1599 瀏覽
添加回答
舉報
0/150
提交
取消