php - 下载文件已损坏 - header

标签 php

我一直在试图找出问题所在,但每次我下载图像并尝试打开它时,它都说文件已损坏。

$h 是从数据库中提取的路径,$h 成功地在页面上显示了图像,但我不明白为什么它不会下载。有任何想法吗 ??

header("Pragma: public"); // required   
header("Cache-Control: private",false); // required for certain browsers  
header('Content-Length: '. filesize("../".$h));  
header('Content-Type: application/octet-stream');  
header('Content-Disposition: inline; filename="'.md5($h).$ext.'"');  
header('Content-Transfer-Encoding:binary');  
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');  

readfile("../".$h);

最佳答案

也许尝试在您的 readfile 行之前添加以下 2 个命令。

ob_clean();
flush();
readfile($file);

这些行在 readfile 上的 PHP 文档示例中。

关于php - 下载文件已损坏 - header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8853568/

相关文章:

php - 在 mysql (codeigniter) 中插入一个外键值

php - 如何用多个id更新mysql中的多条记录

php - Flash 被 ISP 阻止

php - Symfony 控制台 Doctrine :schema:update --force SQLSTATE[HY000] [1045] Access denied for user 'root' @'localhost' (using password: NO)

php wordpress 密码更改-注销我!

php - 在 WordPress 主题中对帖子进行分页

php联系表格干净的代码

php - 从 PHP 中的图像中裁剪空白

php - Mysql查询从users表中获取单个用户数据并从addresses表中获取其所有地址

php - 独立的 php 脚本 : Insert query works fine for large content (300kb), 但 typo3 不保存相同的内容