无法浏览网站,同时下载使用PHP

问题描述:

文件我用这个代码下载文件无法浏览网站,同时下载使用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和火狐

任何答案?

+0

不确定但不要调用flush();定义标题后,只需在输出文件数据时调用该标题。 – 2011-03-31 15:09:12

+0

这是什么答案? – emaillenin 2011-08-21 10:14:52

只有当我知道发生这种情况的时候,你有没有被写入的会话。 我在这里看不到任何会话,所以我不确定是什么导致它。 但是,大多数PHP下载文件脚本用于检查登录,所以我猜这是这种情况。 如果您确实有会话,请尝试session_write_close();

+1

我有这样的问题,这是我的问题的解决方案。谢谢! – CWSpear 2012-06-14 03:45:32

+0

很高兴有帮助。 – frostymarvelous 2012-06-14 15:09:50