DataTable图片不显示且点击后出现404错误求助
问题解决步骤
修正图片URL路径
你的DataTable生成的URL多了public前缀,Laravel存储软链生效后,正确访问路径应为/storage/文件名,而非/public/storage/文件名。修改render函数中的src:{ name: 'file', data: 'file', "render": function (data, type, full, meta) { return "<img src=\"/storage/"+data+"\" height=\"50\"/>"; }, "title": "identity", "orderable": true, "searchable": true, }重新确认storage软链
先删除现有软链再重建,确保链接指向正确:# Linux/Mac系统 rm public/storage php artisan storage:link # Windows系统(命令提示符) rmdir public\storage php artisan storage:link检查项目根目录下的
public/storage是否为指向../storage/app/public的软链接(Windows为快捷方式)。验证文件存储位置
确认上传的图片确实存放在storage/app/public目录下,文件名与数据库记录完全一致(注意Linux系统区分文件名大小写)。检查Laravel配置
打开config/filesystems.php,确保public磁盘配置正确:'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ],同时确认
.env文件中APP_URL设置为http://127.0.0.1:8000。
内容的提问来源于stack exchange,提问作者Ricky Ferdinand
相关产品推荐
相关产品推荐

