You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel中图片无法显示求助:部分图片访问报404错误

Laravel图片访问404问题排查与解决
  • 检查Storage符号链接是否正常
    Laravel需要通过符号链接将storage/app/public映射到public/storage,执行以下命令修复链接:

    rm -rf public/storage
    php artisan storage:link
    
  • 核对访问路径与实际文件路径
    你当前访问的链接是http://127.0.0.1:8000/images/files/Safety/1738837934.png,但实际文件存储在/public/storage/files/Safety/,正确的默认访问路径应为http://127.0.0.1:8000/storage/files/Safety/1738837934.png。
    若你配置了/images作为自定义前缀,需检查两项配置:

    1. 查看config/filesystems.php中public磁盘的url设置是否正确:
      'public' => [
          'driver' => 'local',
          'root' => storage_path('app/public'),
          'url' => env('APP_URL').'/storage',
          'visibility' => 'public',
      ],
      
    2. 检查是否存在路由重写规则,确保/images能正确指向存储目录,示例路由:
      Route::get('/images/{path}', function ($path) {
          return response()->file(storage_path('app/public/'.$path));
      })->where('path', '.*');
      
  • 验证文件权限与存在性

    1. 确认无法显示的图片确实存在于/public/storage/files/Safety/目录,注意Linux系统区分文件名大小写,检查文件名是否与访问链接完全一致。
    2. 设置正确的文件权限,确保Web服务器用户可读取文件:
      chmod -R 755 storage/ public/storage/
      chown -R www-data:www-data storage/ public/storage/ # 根据服务器运行用户调整
      
  • 清除应用缓存
    若之前生成过路由或配置缓存,可能导致规则失效,执行以下命令清除:

    php artisan route:clear
    php artisan config:clear
    

内容的提问来源于stack exchange,提问作者abu abu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 13:02:37