Laravel - 如何获取文件的路径名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27469216/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:33:12 来源:igfitidea点击:
Laravel - how to get path name of file
提问by Incredible
In Laravel im using this code in my controller to get files from directory:
在 Laravel 中,我在控制器中使用此代码从目录中获取文件:
public function galleryImages($album) {
$images = File::allFiles('gallery/'.$album);
return View::make('galleryimages', ['images' => $images]);
}
and in my 'galleryimages' view is:
在我的“galleryimages”视图中是:
@foreach($images as $image)
<img src="???"> <-- how to get file url here?
@endforeach
Now how can I get pathName of $image variable? Var_dump of $image is returning:
现在如何获取 $image 变量的路径名?$image 的 Var_dump 正在返回:
object(Symfony\Component\Finder\SplFileInfo)#247 (4) {
["relativePath":"Symfony\Component\Finder\SplFileInfo":private]=> string(0) ""
["relativePathname":"Symfony\Component\Finder\SplFileInfo":private]=> string(11) "garden5.jpg"
["pathName":"SplFileInfo":private]=> string(25) "gallery/Album/garden5.jpg"
["fileName":"SplFileInfo":private]=> string(11) "garden5.jpg" }
I was trying $image->pathName, but it doesn't work.
我正在尝试 $image->pathName,但它不起作用。