Skip to content Skip to sidebar Skip to footer

Concrete5 - How To Get Files Uploaded Through Ajax In Php

I'm trying to upload multiple files through ajax but I can't figure out how to get the uploaded files in PHP. I sent them var attachments = $('.attachment-file'); var post_data = n

Solution 1:

Working solution:

Here's how you send multiple files with ajax.

JS:

var post_data = newFormData();
attachments.each(function(i, v) {
    post_data.append('my_file[]', v.files[0]);
    console.log(v.files[0]);
});

PHP:

$files = $this->request->files;
$files = $files->get('my_file');
foreach ($filesas$file) {
    \Log::Info(var_dump_safe($file->getClientOriginalName()));
}

It's all working now.

PS. Don't forget not to post and upload files bigger than the PHP limits of post_max_size and upload_max_size!

Post a Comment for "Concrete5 - How To Get Files Uploaded Through Ajax In Php"