在浏览器上使用php查看存储在数据库中的文件

在浏览器上使用php查看存储在数据库中的文件,第1张

在浏览器上使用php查看存储在数据库中的文件

根据您的代码,

$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;


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5618342.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存