是否可以強制下載PHP中的遠程文件而不將其讀入內存?我知道fpassthru(),readfile(),file_get_contents()都會在將文件輸出到瀏覽器之前將它們讀入內存。PHP強制下載遠程文件而不讀入內存
這裏是我的代碼:
if($url = getRemoteFileURL($file_id))
{
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="abc.zip"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Pragma: no-cache');
readfile($url); // is there a better function ?
}
我不想做標題(「位置:」),因爲如果你做一個header("Location: ...");
到下載的文件,將顯示網址
您可以使用分塊獲取遠程文件,並將其分開。但是這需要來自您的腳本的多個http請求,效率非常低。 – 2012-02-11 04:52:02