//取下载文件的头函数
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 直接定位来完成下载的 ,但这样却引发了新的问题,
不能控制下载的文件名了 ,望高手指点
谢谢
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 直接定位来完成下载的 ,但这样却引发了新的问题,
不能控制下载的文件名了 ,望高手指点
谢谢
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));
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=test.xls");
header("Pragma: cache");
header("Expires: 0");