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

Laravel 10图片上传至Storage及网页访问失败问题求助

问题排查与解决步骤
  • 修正存储磁盘配置
    你当前使用Storage::put('profilephotos', $theimagefile)上传时,默认用的是local磁盘,文件会存到storage/app/profilephotos,但软链接指向的是storage/app/public目录,导致URL无法访问。需指定public磁盘上传:

    Storage::disk('public')->put('profilephotos', $theimagefile);
    

    这样文件会被存储到storage/app/public/profilephotos目录,和软链接路径匹配。

  • 验证软链接与文件路径
    执行storage:link后,public/storage映射到storage/app/public,要确保图片实际存放在storage/app/public/profilephotos/12345.jpg,而非storage/app/profilephotos。可以手动查看目录结构确认。

  • 手动重建软链接(Windows环境)
    若自动创建的软链接无效,用管理员权限打开命令提示符,执行以下命令手动创建:

    mklink /D "C:\myproject\public\storage" "C:\myproject\storage\app\public"
    

    执行后检查public/storage目录是否能正常访问到storage/app/public下的文件。

  • 清除应用缓存
    执行以下命令清除配置和缓存,确保存储配置生效:

    php artisan cache:clear
    php artisan config:clear
    
  • 检查目录权限
    确保storage/app/public和public/storage目录拥有读写权限:在Windows上右键目录→属性→安全选项卡,确认当前用户有修改、写入权限。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 08:22:42