I'm currently trying to upload multiple image files using a single form (AJAX) and the Bulletproof library.
I managed to get 1 working, the #avatar-upload-input
successfully uploads images through the AJAX form.
<form method="post" action="ajax/updateprofile" enctype="multipart/form-data" id="dynamicform" data-func="updateprofile">
<input type="file" name="avatar" id="avatar-upload-input" accept="image/*"/>
<input type="file" name="banner" id="banner-upload-input" accept="image/*"/>
</form>
Now I'm trying to get the second one working, but I'm really not sure how I would go and get that working!
I googled it and saw that more people were having the same question, but none really got a clear answer.
It was suggested in the comments of these issues that a loop is needed on $_FILES. I have tried the following:
foreach($_FILES as $file) {
$image = new Bulletproof\Image($file);
$image->setName($Hashids->encode($_SESSION['user_id']) . '-' . uniqid());
$image->setMime(array('jpg', 'png', 'jpeg'));
$image->setLocation('../assets/images/usercontent/pfp');
if($image['avatar']){
$upload_pfp = $image->upload();
bulletproof\utils\resize($upload_pfp->getFullPath(), $upload_pfp->getMime(), $upload_pfp->getWidth(), $upload_pfp->getHeight(), 190, 175);
}
}
That didn't gave me any errors but also didn't upload any image.
I hope someone can help me solve how can I upload multiple images using the mentioned library!