我想上传多个图像文件并通过电子邮件发送给客户。但是 ajax 请求在添加到 dropzonecall to a member function getclientoriginalname() on array时会出现此错误。uploadMultiple: true,没有该选项的多张图片上传。无论如何,我想通过电子邮件发送多个文件,我该怎么做?拖放区 js 代码:Dropzone.options.uploadimg = { paramName: "file", // The name that will be used to transfer the file maxFilesize: 5, //MB acceptedFiles: ".jpeg,.jpg,.png", uploadMultiple: true, addRemoveLinks: true, success: function(file, response) { $.notify({ message: 'Image uploaded Successfully!' }, { type: 'success' }); }, error: function(file, response) { return false; console.log('fail to upload'); }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }SendMailController 发送上传的图片。 public function sendNotifications(Request $request) { $id_int = Cookie::get('jobid'); $img_name = Cookie::get('imgName'); $data = DB::table('customers') ->join('jobs', 'jobs.id', '=', 'customers.id') ->select('firstname','email') ->where('jobs.id', '=', $id_int) ->get()->toArray(); foreach ($data as $value) { $customer_firstname = $value->firstname; $customer_email = $value->email; } $pathToFile = public_path() . "\\uploads\\" . $img_name; //send the email to the relevant customer email Mail::to($customer_email)->send(new SendMail($customer_firstname, $pathToFile), function($message){ $message->attach($pathToFile); }); }当我上传多张图片并通过电子邮件发送时,它只会在 dropzone 中发送最后上传的文件。如何发送所有上传的文件?
1 回答

慕码人2483693
TA贡献1860条经验 获得超9个赞
因为它有多个文件,您需要遍历文件变量来获取文件
class ImageUploadController extends Controller
{
public function uploadImage(Request $request){
$img_files = $request->file('file');
foreach($img_files as $img_file){
$imgName = $img_file->getClientOriginalName();
Cookie::queue(cookie('imgName', $imgName, $minute = 5));
$img_file->move(public_path('uploads'), $imgName);
}
}
}
- 1 回答
- 0 关注
- 150 浏览
添加回答
举报
0/150
提交
取消