gpt4 book ai didi

javascript - 使用 dropzone laravel 通过电子邮件发送多个图像

转载 作者:行者123 更新时间:2023-11-30 19:00:46 24 4
gpt4 key购买 nike

我想上传多个图像文件并通过电子邮件发送给客户。但是当 uploadMultiple: true, 添加到 dropzone 时,ajax 请求得到这个错误 call to a member function getclientoriginalname() on array。未使用该选项上传多张图片。不管怎样,我想通过电子邮件发送多个文件,我该怎么做?

dropzone 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);
});

}

图片上传 Controller :

class ImageUploadController extends Controller
{
public function uploadImage(Request $request){

$img_file = $request->file('file');

$imgName = $img_file->getClientOriginalName();

Cookie::queue(cookie('imgName', $imgName, $minute = 5));

$img_file->move(public_path('uploads'), $imgName);
}
}

当我上传多张图片并通过电子邮件发送时,它只会发送 dropzone 中最后上传的文件。我怎样才能发送所有上传的文件?

最佳答案

由于它有多个文件,你需要循环遍历文件变量来获取文件

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);
}
}
}

关于javascript - 使用 dropzone laravel 通过电子邮件发送多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59529323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com