我想上傳多個圖像文件并通過電子郵件發送給客戶。但是 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 關注
- 149 瀏覽
添加回答
舉報
0/150
提交
取消