我遇到了大小超过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');'
答案 0 :(得分:0)
源代码:
<?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>";?>
?>