0

此代码段应通过网络将文件tiffmodi从 Web 服务器传输到用户

header('Content-Description: File Transfer');
header('Content-Type: ' . $file_mime_type);
header('Content-Disposition: attachment; filename="' . $file_name . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . $file_size);

# till this moment all is fine
echo file_get_contents("path/to/file.tif");
# script fails on line above, and doesnt reach this place

当文件格式不是 tiff 或 modi 时,一切正常,客户端浏览器开始下载文件(docx/xlsx/pdf/等)当用户尝试下载 tiff 或 modi 时,脚本失败且没有任何错误。试过print(file_get_contents("path/to/file.tif")); readfile("path/to/file.tif"); 而不是回声,结果是一样的

4

1 回答 1

0

当我开始使用“通用”内容类型时,一切正常

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream'); //universal Content-Type
header('Content-Disposition: attachment; filename="' . $file_name . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . $file_size);

echo file_get_contents("path/to/file.tif");
于 2017-09-25T14:05:12.480 回答