Here are the inputs I want to loop through
Main photo: <input type="file" name="image[]" />
Side photo 1: <input type="file" name="image[]" />
Side photo 2: <input type="file" name="image[]" />
Side photo 3: <input type="file" name="image[]" />
A couple weird things happened, when I uploaded nothing I use the count($_FILES['image'])
, I echoed that function, and it returns a value of 5. There should be no elements in that array. Why is there one extra input when I only have 4 files to begin with?
Now with the actually looping itself, I try using the foreach loop, but it doesn't work.
foreach($_FILES['image'] as $files){echo $files['name']; }
Nothing came up, what I wanted to ultimately do is to loop through all images, make sure they are correct format, size, and rename each of them. But this simple foreach() loop shows that somehow I can't even loop through the $_FILES array and the count() confused me even more when it say that there are 5 elements in the array when I didn't even upload anything.
just rename your fields this way
and then you'll be able to iterate it usual way: