【发布时间】:2019-04-04 00:05:08
【问题描述】:
我想通过路由访问存储在 laravel 中公用文件夹中的图像,以防搜索图像是否存在于我的公用文件夹中,到目前为止,这是我的代码:
api.php
Route::group(['prefix' => 'images', 'middleware' => 'cors'], function () {
Route::get('itemsImages/{imagename}','ManagerController@itemImage');
});
ManagerController.php
public function itemImage($imagename)
{
// Check if file exists in storage directory
$file_path = public_path() .'/images/itemsImages/'.$imagename;
if (file_exists($file_path))
return Response::download($file_path);
else
dd($file_path);
//does not exist
}
但该代码不起作用,甚至无法访问该路线,任何帮助将不胜感激,谢谢。
【问题讨论】:
-
你注册了你的中间件吗?
-
是的,我当然做到了。
-
检查
laravel.log上的错误,并检查您在尝试访问该网址时收到的返回码和消息。如果可能,请在此处发布结果。 -
能否请您提及所需的路径?你想得到的。
-
在更改 url 后尝试
dd方法中的文件名。