【发布时间】:2016-08-22 18:33:44
【问题描述】:
我对超薄框架非常陌生,我正在尝试下载图像文件。使用 php 在本地工作正常。但是当在服务器上应用相同的代码时,它不起作用。搜索了很多但没有运气,即here 和this one。这是我的代码
$app->get('/image', function ($request, $response, $args) {
//header('Content-type: image/png');
//header('Content-Disposition: attachment; filename=go-logo.jpg');
//$contents = file_get_contents(getcwd() . '/' . $_GET['img']);
$filename=getcwd() . '/' . $_GET['img'];
header("Content-Length: " . filesize($filename));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=go-logo.jpg');
readfile($filename);
return $contents;
});
错误是它显示它是一个 html 文件。我想要这样的
【问题讨论】:
-
不工作是什么意思?
$contents也没有在任何地方定义。 -
对不起。我忘了附上屏幕短片
-
请立即查看
-
您是否下载了图像并使用编辑器打开?这可能是服务器给出的错误页面。
标签: php image content-type slim