我正在使用这种方法来上传我的图像
mkdir(public_path().'/website/'.$path,0777, true);
它应该在根文件夹(Public_html)上创建它,但我发现它是在名称(公共)的新文件夹上创建的,所以现在我无法使用此代码获取图像的路径
<img src="{{url('public/website/'.$file->path.$file->file)}}" />
如何获取图像的正确路径,甚至在public_html根路径上创建文件夹?
试试这个以获得图像
<img src="<?php echo public_path().'/website/'.$path.$file->file; ?>" />
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}}" />
您尝试这样来获取图像内容
<img src="<?php echo asset('/').'public/'.$path.$file->file; ?>" />
您可以使用laravel helper功能资产。 $ url = asset('img / photo.jpg');那么你将获得公共目录的完整路径。 $ url返回www.your.domain.com/public/img/photo.jpg
我没有测试过但是......你有没有试过这种方式?
mkdir(public_path('/website/'.$path),0777, true);
对我来说,如果我没有错,你的问题可能只是写作问题。