【发布时间】:2019-05-07 05:15:08
【问题描述】:
我使用 Nginx + PHP-FPM 和 Amazon Linux 2 服务器。
我有一个名为 myplugin.zip 的文件,大小为 34KB
[root@ip-172-33-4-164 laravel-app]# ls -la /tmp/R2birI4LuZ/myplugin.zip
-rw-r--r-- 1 nginx nginx 35889 May 6 16:21 /tmp/R2birI4LuZ/myplugin.zip
在 lunix 上使用“unzip”完美解压文件。
但是,当我尝试使用 Symfony 的 Binary 类将文件作为响应发送时:
$path = /tmp/R2birI4LuZ/myplugin.zip;
$headers = [
'Content-Type' => 'application/zip',
'Content-Transfer-Encoding' => 'Binary',
'Content-Disposition' => 'attachment; filename='.basename($path),
"Content-Length: ".filesize($path)
];
$response = new \Symfony\Component\HttpFoundation\BinaryFileResponse($path, 200 , $headers);
return $response;
我也试过了
通过 Chrome 返回到我的 MacOS 的文件大小错误且已损坏
-rw-r--r--@ 1 Dev-Mac staff 59940 May 6 18:21 myplugin.zip
请注意,我还尝试了以下 Laravel download() 并返回相同的大小(59940 字节): https://laravel.com/docs/5.8/responses#file-downloads
【问题讨论】: