[英]Php header redirecting for file force download not working
我遇到了標題重定向問題,並強制下載大小大於1GB的文件。
此代碼適用於大小小於1GB的文件
ini_set('memory_limit', '18364M');
header('Content-Type: application/bin');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="download.bin"');
readfile('Setup.bin');'
你可以試試看嗎? PHP腳本強制使用塊下載大文件
源代碼:
<?php
$file = dirname(__FILE__) . "/Setup.bin";
if (file_exists($file)) {
if (FALSE !== ($handler = fopen($file, 'r'))) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: chunked'); //changed to chunked
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
//Send the content in chunks
while (false !== ($chunk = fread($handler, 4096))) {
echo $chunk;
}
}
exit;
}
echo "<h1>Content error</h1><p>The file does not exist!</p>";?>
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.