I have created an html form with a php back-end that allows for up to two image uploads. Everything works just fine when a user submits two images, but the submission fails if there are one or no images attached. I know why this is happening, but need a tiny bit of help.
My php is set up to handle a variable number of images, but I am missing one important detail that is preventing it from working - I don't know how to get a count of the total number of attached images.
Here is my html:
<div class="field">
Select first image to upload:
<input type="file" name="fileToUpload[0]" id="fileToUpload">
</div>
<div class="field">
Select second image to upload:
<input type="file" name="fileToUpload[1]" id="fileToUpload">
</div>
In the beginning of my php, I was trying to get the count of images using $total_images = count($_FILES['fileToUpload']['name']);
, but this always returns '2' since it is counting the fields and not the fields with attachments.
How can I get a count of the number of fields with attachments, not just the total number of fields?
Thank you very much.