Javascript 图像无法渲染,路径基于存储路径
我的控制器上有这个功能Javascript 图像无法渲染,路径基于存储路径,javascript,jquery,image,laravel,laravel-5.2,Javascript,Jquery,Image,Laravel,Laravel 5.2,我的控制器上有这个功能 public function get_images(Request $request){ $images = inventory_images::where('item_id',$request->id)->get(); $path = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix(); return response()->
public function get_images(Request $request){
$images = inventory_images::where('item_id',$request->id)->get();
$path = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
return response()->json([ 'success' => true, 'images' => $images, 'id' => $request->id, 'path' => $path ]);
}
因此,“$path”包含存储路径,“$images”包含存储在“storage”文件夹中的图像,“$images”包含文件名,然后在我的前端(渲染图像)
$。每个(如图像、函数(索引、值){
$(“#通知#对话框#库项容器”)。附加(“”);
});
在图像'src'中,我有以下路径
C:\wamp\www\Clinic和Inventory
系统\storage\app\public\items\u gallery\10014589\u 974440645904700\u 5867266076580720168\u n.jpg
在控制台中,我有这个错误
:1不允许加载本地资源:
file:///C:/wamp/www/Clinic%20and%20Inventory%20System/storage/app/public/items_gallery/10014589_974440645904700_5867266076580720168_n.jpg
图像没有渲染,如果我将路径粘贴到浏览器,我可以看到图像,这意味着路径正确,只是图像没有渲染,有什么想法,请提供帮助?在保存图像的标记上添加数据属性:
data-image_path="{{ asset('uploads/*name of model this is being associated with/original/') }}"
其中,资产指向项目的公共目录
然后从控制器中检索图像名称并将其附加到该路径 我在某处找到了解决办法
Route::get('/images/{image}', function($image = null)
{
$path = storage_path().'/app/public/items_gallery/' . $image;
if (file_exists($path)) {
return Response::download($path);
}
});
现在一切正常。正如我所说,图像位于存储文件夹中,而不是位于公用文件夹中。您的存储文件夹中有“/app/public/items\u gallery/”吗?
Route::get('/images/{image}', function($image = null)
{
$path = storage_path().'/app/public/items_gallery/' . $image;
if (file_exists($path)) {
return Response::download($path);
}
});