php - Slim 3 Framework 下载文件不显示下载对话框
问题描述
我尝试下载文件 .png 使用带有此代码的 Slim 3:
$app->get('/api/download/content/image/{filename}', function($request, Slim\Http\Response $response, $args) {
$file = __DIR__ . '/uploads/content/image/'. $args['filename'];
$fh = fopen($file, 'rb');
$stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body
return $response->withHeader('Content-Type', 'application/force-download')
->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Type', 'application/download')
->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Content-Disposition', 'attachment; filename="' . basename($file) . '"')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->withHeader('Pragma', 'public')
->withBody($stream); });
但下载对话框不显示。只显示字符串
解决方案
推荐阅读
- python - 如何在多列上执行 TTest
- flutter - 如何递归地对 listview.builder 执行操作?
- c - 如果我的机器上的 sizeof(long) 是 4 个字节,我可以推断 sizeof(long long) 是 8 个字节吗?
- python - 将数据类型从 yyyy-MM-dd 格式的 String 更改为 DateType
- php - PHP 在 Smarty .conf 文本文件中使用定义的全局变量
- javascript - Ionic Firebase 数据库卡
- xilinx - 找不到 C:\Xilinx\xic\bin\xic.bat
- c# - C# 中的“列名无效”
- html - 如何通过以下方式订购 HTML 页面?
- javascript - OpenWebStart + IcedTea-Web:JavaScript 启动按钮