2

I have my basic form that's used to capture two images from the user. (hiding other parts of the form)

<form name="myform" id="myform" action="submit.php" method="post" enctype="multipart/form-data">
  <input type="file" id="image" name="images[]" accept="image/*" capture="camera" />
  <input type="file" id="image" name="images[]" accept="image/*" capture="camera" />
  <input type="file" id="image" name="images[]" accept="image/*" capture="camera" />
</form>

It work fine manually adding phones and adding photos straight from the camera on android. But on iPhone it will only upload the last photo taken with the camera (manually adding files works fine still).

So for example if I take a picture for input #1, add one manually for input #2, and take a picture for input #3. Only #2 and #3 will be uploaded.

My best guess is the iPhone camera has some weird cache thing and it gets rid of the first one.

The upload code is fairly similar to templates I've found and, like I stated, works for all cases except for the above.

$countfiles = count($_FILES['images']['name']);
for($i = 0; $i < $countfiles; $i++){
  $image_name[$i] = $_FILES['images']['name'][$i];
  move_uploaded_file($_FILES['images']['tmp_name'][$i],'upload/'.$image_name[$i]);
}
canpan14
  • 1,181
  • 1
  • 14
  • 36
  • 1
    Don't use the name provided by the client for storage. Try using some other identifier, or a random name instead. – miken32 May 08 '19 at 21:11
  • 1
    To extend from @miken32's idea with a basis of a solution, on the client-side HTML you could generate a group of the name's such as "image-1526" and "image-5913" using a PHP's Random, then server-side get them into an array by checking each post "image-" and pushing. – Jack Hales May 08 '19 at 21:29
  • 1
    Elements can't have the same ID. This may or may not be causing unexpected behaviour. I'd take the current adivce from miken and jack and also edit the ID's – Second2None May 08 '19 at 22:18
  • Thanks for the comments! I agree with the ID thing. I was mostly learning from an example and they did that so I didn't mind it at the time since it seemed to be working. I will try the solution from that other post, it seems extremely similar. – canpan14 May 09 '19 at 00:49
  • 1
    @Second2None ID attributes have nothing to do with server-side, but definitely good practice to fix them anyway. – miken32 May 09 '19 at 21:16
  • 1
    @miken32 indeed it doesn't but the files must be loaded on the client side, which does require unique ID's, it was just a note which is why I added he should take your advice but also change the ID's. – Second2None May 10 '19 at 22:05

0 Answers0