为了账号安全,请及时绑定邮箱和手机立即绑定

使用 dropzone laravel 通过电子邮件发送多张图片

使用 dropzone laravel 通过电子邮件发送多张图片

PHP
Smart猫小萌 2022-07-09 10:57:34
我想上传多个图像文件并通过电子邮件发送给客户。但是 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);

        }

    }

}


查看完整回答
反对 回复 2022-07-09
  • 1 回答
  • 0 关注
  • 150 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号