点击CV下载按钮出现404 NOT FOUND问题求助
解决CV下载404错误的方案
问题定位
访问URL出现重复的cv_files路径(如http://localhost/storage/cv_files/cv_files/xxx.pdf),说明代码中拼接的路径与数据库存储的文件路径重复叠加,同时需确认文件存放位置是否符合符号链接的访问规则。
具体修复步骤
- 检查数据库存储值:查看
student表的cv_file字段,确认是否已包含cv_files/前缀(例如存储值为cv_files/IrF7GnM9QXLehTjOwV4a9K5HiaQLwfUKQEU7LNgR.pdf)。 - 修正前端代码:如果字段已包含路径前缀,移除代码中额外的
cv_files/,改为:
<td class="border px-4 py-2"><a href="{{ asset('storage/' . $student->cv_file) }}">{{ $student->cv_file }}</a></td>
- 确认文件存储位置:执行
php artisan storage:link后,只有storage/app/public目录下的文件能通过public/storage访问。若文件在storage/app/cv_files,需将其移动到storage/app/public/cv_files;或修改config/filesystems.php,新增自定义磁盘并创建对应符号链接:
然后手动创建符号链接:'disks' => [ // ...其他配置 'cv_files' => [ 'driver' => 'local', 'root' => storage_path('app/cv_files'), 'url' => env('APP_URL').'/cv_files', 'visibility' => 'public', ], ]ln -s /path/to/laravel/storage/app/cv_files /path/to/laravel/public/cv_files - 替代方案:使用Storage门面:若文件在
storage/app/public/cv_files,可直接用Storage::url()生成正确路径:
<td class="border px-4 py-2"><a href="{{ Storage::url('cv_files/' . $student->cv_file) }}">{{ $student->cv_file }}</a></td>
内容的提问来源于stack exchange,提问作者Vishal Kumar
相关产品推荐
相关产品推荐

