laravel 获取laravel公用文件夹中的图像路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43113574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting image path in public folder in laravel
提问by Dina Shaldoum
I'm making direction using this method to upload my image
我正在使用这种方法上传我的图片
mkdir(public_path().'/website/'.$path,0777, true);
It's supposed to create it on the root folder (Public_html) , but i found it created on new folder with name (public ) , so now i can't get the path of the image using this code
它应该在根文件夹 (Public_html) 上创建它,但我发现它是在名称为 (public) 的新文件夹上创建的,所以现在我无法使用此代码获取图像的路径
<img src="{{url('public/website/'.$file->path.$file->file)}}" />
how to get the correct path of the image or even create the folder on the public_html root path ?
如何获取图像的正确路径,甚至在 public_html 根路径上创建文件夹?
回答by ram pratap singh
Try this to get image
试试这个来获取图像
<img src="<?php echo public_path().'/website/'.$path.$file->file; ?>" />
回答by Andranik Petrosyan
you can use public_path(); function in laravel
or
<img src="{{ public_path().'/website/'.$file->path.'/'.$file->file;}}" />
or
<img src="/website/{{$file->path.$file->file}}" />
回答by ram pratap singh
You try this to get your image content
你试试这个来获取你的图像内容
<img src="<?php echo asset('/').'public/'.$path.$file->file; ?>" />
回答by Jagdish Chaudhary
You can use laravel helper function asset for eg. $url = asset('img/photo.jpg'); then you will get full path with public directory. $url return www.your.domain.com/public/img/photo.jpg
您可以使用 laravel 辅助功能资产,例如。$url = asset('img/photo.jpg'); 然后您将获得公共目录的完整路径。$url 返回 www.your.domain.com/public/img/photo.jpg
回答by Necare
I didn't tested it but... did you have tried this way?
我没有测试过,但是……你试过这种方式吗?
mkdir(public_path('/website/'.$path),0777, true);
To me, if I'm not wrong your problem could be only a matter of writing.
对我来说,如果我没记错的话,你的问题可能只是写作问题。