在laravel中的公共文件夹中获取图像路径

问题描述 投票:0回答:5

我正在使用这种方法来上传我的图像

 mkdir(public_path().'/website/'.$path,0777, true);

它应该在根文件夹(Public_html)上创建它,但我发现它是在名称(公共)的新文件夹上创建的,所以现在我无法使用此代码获取图像的路径

 <img src="{{url('public/website/'.$file->path.$file->file)}}"  />

如何获取图像的正确路径,甚至在public_html根路径上创建文件夹?

php laravel
5个回答
0
投票

试试这个以获得图像

 <img src="<?php echo public_path().'/website/'.$path.$file->file;  ?>"  />

0
投票
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}}"  />

0
投票

您尝试这样来获取图像内容

  <img src="<?php echo asset('/').'public/'.$path.$file->file;  ?>"  />

0
投票

See Here for more info

您可以使用laravel helper功能资产。 $ url = asset('img / photo.jpg');那么你将获得公共目录的完整路径。 $ url返回www.your.domain.com/public/img/photo.jpg


0
投票

我没有测试过但是......你有没有试过这种方式?

mkdir(public_path('/website/'.$path),0777, true);

对我来说,如果我没有错,你的问题可能只是写作问题。

© www.soinside.com 2019 - 2024. All rights reserved.