根据您的代码,$row[1]
是“文件名”。Content type标头应改为包含 @H_404_3@内容类型 ,即文件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需要一些 @H_404_3@临时 插件。
一个更完整的例子 @H_404_3@右出的手册 ,让你更彻底的了解(并非所有的标题是必要的,你应该相应改变别人对你的代码):
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-@R_864_301@: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;