在我的本地计算机项目工作文件上但是当我上传到我的服务器上时,所有图像都没有显示,并且当我点击浏览器的完整图像路径时出现NotFoundHttpException错误。
项目的mypath为
/public_html/offlinemall/public
以下是我的filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
'featured' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
],
我是如何获得形象的
<img style="height: 480px" src="storage/{{ $ad->avatar }}">
在检查中我得到完整路径但是当我点击url然后我得到NotFoundHttpException错误。
http://compare.theofflinemall.com/storage/featured_image/qzHWpQeSfKjZ6DOS59ROyYboJ1GCvVi6NNVfLtVV.jpeg
答案 0 :(得分:3)
基本上,它具有象征性的问题。可能您已使用存储目录来存储图像。如果使用它,则需要通过php artisan storage:link
创建符号链接。它将使用存储名称在本地项目的公共目录中创建一个符号目录。当您在服务器上上传项目时,符号目录将不会随您的项目一起上传。因此,合理地说,浏览器不会获取路径,也不会显示图像。从这些角度来看,有许多解决方案:
解决方案1::如果您具有服务器的ssh密钥访问权限,请使用ssh密钥登录到服务器,然后转到项目目录并运行命令php artisan storage:link
为您的项目创建符号目录。
解决方案2::在服务器上创建cron作业。
解决方案3:通过执行php脚本来创建符号链接。请通过此链接cron job and php file execution。
解决方案4::通过更改config / filesystem.php中映像路径的根目录。请通过此网址laracast.com
答案 1 :(得分:1)
您的服务器无法找到storage
作为路径,因为它使用public_path
跑
php artisan storage:link
它应该工作。另外,尝试使用
{{ asset('storage/'.$ad->avatar) }}
答案 2 :(得分:0)
您可以将图片标记更改为:
<img src={{ asset('storage/'.$ad->avatar) }} />
<img src="storage/app/public/{{$ad->avatar) }}" />
<img src="<?php echo asset("storage/app/public/$ad->avatar")?>"></img>