laravel - LARAVEL - 多个文件上传不起作用和检索
问题描述
当我点击提交时,它只存储最后选择的文件,它应该存储所有图像以及如何检索这些文件?有什么建议或例子吗?我需要为多个文件设置不同的属性吗?
控制器
if (is_array($request->carEvidence)) {
foreach ($request->carEvidence as $key => $file) {
$destinationPath = public_path('image/');
$profileImage = $key . "-" . date('YmdHis') . "." . $file->getClientOriginalExtension();
$file->move($destinationPath, $profileImage);
$post['carEvidence'] = "$profileImage";
}
}
意见
<input type="file" name="carEvidence[]" multiple>
MYSQL https://ibb.co/9sPLw8C
解决方案
你在数组中传递多个文件,所以你必须使用循环来检索控制器中的所有文件..类似
if (is_array($request->carEvidence))
{
foreach ($request->carEvidence as $key => $file) {
$destinationPath = public_path('image/');
$profileImage = $key."-".date('YmdHis') . "." . $file->getClientOriginalExtension();
$file->move($destinationPath, $profileImage);
// code to save in your db table
}
}
推荐阅读
- android - UnityEngine.Microphone.devices.Length = 0
- android - requestPermissions 按钮上的不可见文本
- python - 基于另一个规则的新列(在值中包含一个数字)
- css - 在悬停时更改 React 中的背景颜色
- java - 无法模拟 Rest Template postForEntity()
- javascript - 使用表单 onsubmit 不触发 javascript 而是重新加载页面
- typescript - 具有自引用通用类型的记录
- python - TOR Stem 找不到 cookie 控制身份验证文件
- mysql - 带有嵌套表的 SQL 连接返回错误数据
- javascript - JavaScript 变量到 SQL