根据您的代码,
$row[1]是“文件名”。Content type标头应改为包含 内容类型 ,即文件mime类型,例如:
header('Content-type: application/pdf');如果要添加文件名:
header('Content-type: application/pdf');header('Content-Disposition: attachment; filename='.$row[1]);print $data;确保
$data文件的内容,例如可以从readfile()获取的内容。
在手册上阅读更多信息:http :
//php.net/manual/en/function.readfile.php
请记住,尽管浏览器可以轻松查看PDF和图像,但我认为Excel需要一些 临时 插件。
一个更完整的例子 右出的手册 ,让你更彻底的了解(并非所有的标题是必要的,你应该相应改变别人对你的代码):
header('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename='.basename($file));header('Content-Transfer-Encoding: binary');header('Expires: 0');header('Cache-Control: must-revalidate');header('Pragma: public');header('Content-Length: ' . filesize($file));ob_clean();flush();readfile($file);exit;


