Php 流文件已损坏
每次我使用下面的代码将图像文件流式传输给我时,文件都会被视为已损坏。不过,图像文件肯定没有损坏,当我通过ftp打开它时,它是正常的。我错过什么了吗Php 流文件已损坏,php,download,Php,Download,每次我使用下面的代码将图像文件流式传输给我时,文件都会被视为已损坏。不过,图像文件肯定没有损坏,当我通过ftp打开它时,它是正常的。我错过什么了吗 $fileTry = imagecreatefromstring(file_get_contents($file_path)); if($fileTry === false) { die('no file'); } else { header('Content-Description: File Transfer');
$fileTry = imagecreatefromstring(file_get_contents($file_path));
if($fileTry === false)
{
die('no file');
}
else
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file_path));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
readfile($file_path);
exit;
}
你知道它的类型吗?为什么要使用
application/octet-stream
而不是它的实际mime类型?如果你不知道它的类型,我想octet的工作原理是一样的?我不确定它是否会。使用您正在测试的已知文件类型进行测试:image/jpeg
例如或image/png
。将代码更改为标头('Content-type:'。将图像类型更改为mime类型($file\u path));我也有同样的问题。图像总是被损坏。