您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

根据您的代码$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;
php 2022/1/1 18:53:17 有511人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶