无法使用php下载文件时浏览网站
我用这个代码来下载文件
$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上
任何答案?
只有当我知道发生这种情况的时候,你有没有写过的会话。 我在这里看不到任何会话,所以我不确定是什么原因造成的。 但是,大多数php下载文件脚本都用于检查登录,所以我猜这是事实。 如果您有会话,请尝试session_write_close();
链接地址: http://www.djcxy.com/p/45511.html上一篇: Unable to browse the site while downloading a file using php
