//取下载文件的头函数
function genHeadDownloadFile($filepath)
{
if (is_file($filepath))
{
$filename = basename($filepath);
$position = strrpos($filename, ".");
$extendname = strtolower(substr($filename,$position + 1));
header("Content-type: application/octet-stream;");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($filepath));
header("Content-Disposition: attachment; filename=".$filename);
@readfile($filepath);
}
die;
}这样不能弹出下载框 ,而是直接将Excel 中的数据现在在页面中,不明白为什么会这样 ,最后用到js 直接定位来完成下载的 ,但这样却引发了新的问题,
不能控制下载的文件名了 ,望高手指点
谢谢

解决方案 »

  1.   


     header("Pragma: public"); 
            header("Expires: 0"); 
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
            header("Cache-Control: private",false); 
            header("Content-Type: application/zip"); 
            header("Content-Disposition: attachment; filename=".basename($archiveName).";" ); 
            header("Content-Transfer-Encoding: binary"); 
            header("Content-Length: ".filesize($archiveName));
      

  2.   

    用如下代码可以,已经测试过。
    header("Content-Type: application/vnd.ms-excel"); 
    header("Content-Disposition: attachment; filename=test.xls"); 
    header("Pragma: cache"); 
    header("Expires: 0"); 
      

  3.   

    header("Content-Disposition: attachment; filename=".$filename); $filename最好是一个容易识别的字串
      

  4.   

    支持莱西第一城 www.laixihome.com