我一直在试图找出问题所在,但每次我下载图像并尝试打开它时,它都说文件已损坏。
$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/