I have multiple input fields with the same name. they look like:
<input type="hidden" class="image-hidden" name="image-to-upload[]" />
<input type="hidden" class="image-hidden" name="image-to-upload[]" />
<input type="hidden" class="image-hidden" name="image-to-upload[]" />
<input type="hidden" class="image-hidden" name="image-to-upload[]" />
...
...
I am uploading with this code:
<?php
if(isset($_POST['new-blogpost'])) {
$img = $_POST['image-to-upload'][0];
$img = str_replace('data:image/jpeg;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = 'image.jpg';
$success = file_put_contents($file, $data);
};
?>
the problem is, this code will only upload the first input fields picture.
How do I have to rewrite my code to upload all input fields? (I know that I have to give my files unique names in that case, but thats no my question. I'm wondering how to tell PHP it has to loop through all the input fields and do the upload.
Thanks in advance!