我用这段代码下载文件
$file='test.mp3';
$download_rate = 50; //50 kb/s
if(file_exists($file) && is_file($file))
{
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($file));
header('Content-Disposition: filename='.$file);
flush();
$file = fopen($file, "r");
while(!feof($file))
{
// send the current file part to the browser
print fread($file, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
sleep(1);
}
fclose($file);
}
else {
echo 'File Not Found';
}
但下载文件时无法浏览网站,直到下载完成 . 这发生在IE和Firefox上
任何答案?
1 回答
只有当你有没有写过的会话时,我才知道这种情况发生了 . 我在这里看不到任何会话,所以我不确定是什么导致它 . 但是,大多数php下载文件脚本用于检查登录,所以我猜这是这种情况 . 如果你有会话,请尝试session_write_close();