我使用此代码下载文件
$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上
有什么答案吗?
答案 0 :(得分:3)
只有当我知道会发生这种情况时才会发生这种情况。 我在这里看不到任何会话,所以我不确定是什么导致它。 但是,大多数php下载文件脚本用于检查登录,所以我猜这是这种情况。 如果你有会话,请尝试session_write_close();