Laravel:download()不会触发文件保存对话框
我的 laravel(8.0) 测试代码 (web.php):
Route::get(
'/dddd',
fn () =>
response()->download(public_path('version.pdf'), null, ['Content-Type' => 'application/pdf'])
);
此代码在我的宅基地测试环境中运行得很好。浏览器将弹出一个文件对话框并要求用户保存文件。
但是,当我将此应用程序放入 docker 中时(图片:php:8.0-apache-buster),弹出对话框将不会显示,浏览器会直接使用二进制字符打开文件。我尝试在 chrome 中捕获响应,响应标头如下所示:
Request URL: http://redtrain.test:8080/dddd
Request Method: GET
Status Code: 200 OK
Remote Address: 192.168.10.10:8080
Referrer Policy: strict-origin-when-cross-origin
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 1305
Content-Type: text/html; charset=UTF-8
Date: Fri, 04 Mar 2022 05:39:56 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.38 (Debian)
Vary: Accept-Encoding
X-Powered-By: PHP/8.0.14
我注意到标头与我的代码不一致,也许它是由 Apache 更新的?有人可以给我一些提示吗?
My laravel(8.0) test code (web.php):
Route::get(
'/dddd',
fn () =>
response()->download(public_path('version.pdf'), null, ['Content-Type' => 'application/pdf'])
);
This code works perfert in my homestead test environment. The browser will popup a file dialog and ask user to save the file.
But when I put this application inside docker (image: php:8.0-apache-buster), the popup dialog will not show and the browser open the file directly with binary characters. I tried to catch the response in chrome, the response headers is like following:
Request URL: http://redtrain.test:8080/dddd
Request Method: GET
Status Code: 200 OK
Remote Address: 192.168.10.10:8080
Referrer Policy: strict-origin-when-cross-origin
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 1305
Content-Type: text/html; charset=UTF-8
Date: Fri, 04 Mar 2022 05:39:56 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.38 (Debian)
Vary: Accept-Encoding
X-Powered-By: PHP/8.0.14
I noticed that header is not consistent with my code, maybe it is updated by Apache? Can someone give me some hint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论