【发布时间】:2019-01-25 20:11:05
【问题描述】:
我在公用文件夹以外的存储文件夹中有一个图像和一些文本文件。文件夹架构是 贮存 |->上传
并设置类似的路线
Route::get('storage/{folder}/{filename}','FileController@getFile');
在控制器内部,getFile 方法有以下代码
$path = storage_path($folder . DIRECTORY_SEPARATOR . $filename);
if (extension_loaded('fileinfo')) {
if (!File::exists($path)) {
abort(404);
}
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
}
else{
abort(412,'please enable the fileinfo extension or contact site administration');
}
当我尝试从 url 检索图像时,它会返回像这样的空白图像 blank image
但是当我尝试检索文本文件时,它会返回文件
当 mime 类型为 image/* 时,还尝试使用 Image::make($path) 和 response()->file($path),但输出仍然相同..
那么如何在不使用公共文件夹的情况下从 url 显示我的图像文件
【问题讨论】:
-
已经尝试过from here的解决方案,但是不行
标签: php laravel file-handling