gpt4 book ai didi

php - Laravel 5.1 - 显示存储在存储文件夹中的图像

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:49:37 24 4
gpt4 key购买 nike

我正在使用 Laravel 5.1 为网站制作图片上传功能。由于安全问题,我想将这些图像存储在/storage/app 文件夹中,而不是/public。图片的网址,例如:

/storage/app/images/<image_name>

为了从/storage/app获取图片,我为此设置了一个特定的路由:

http://app.com/image/<image_name>

将图像请求指向/storage:

Route::controllers([
'image' => 'Frontend\ImageController',
]);

ImageController 中,这里是创建响应的代码:

public function missingMethod($filename = [])
{
if (is_array($filename)) {
$filename = implode('/', $filename);
}
// storage_path('app') - path to /storage/app folder
$path = storage_path('app') . '/' . $filename;
$file = \File::get($path);
$type = \File::mimeType($path);

return \Response::make($file,200)
->header("Content-Type", $type);
}

我的问题是,在使用此路由检索图像后,我无法在我的 View 中显示它们。没有 404、500 或任何错误状态代码,应该是请求 URL,但它只是显示一个损坏的图像图标。我的代码有什么问题吗?

谢谢!

最佳答案

对不起各位,我的/config文件夹中的一个php脚本有前导空格,导致http响应失败@@这么无意义的错误...谢谢大家的帮助!

关于php - Laravel 5.1 - 显示存储在存储文件夹中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34757026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com