Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to use upload images it works perfect in browser but it doesn't work in iphone and ipad .below are code and screenshots for iphone

test.php
---------
<?php 
    if(isset($_POST['submit']))
    {
        //echo "<pre>";
        //print_r($_FILES);
        //exit;
        copy($_FILES["image1"]["tmp_name"],"upload/".$_FILES["image1"]["name"]);
        copy($_FILES["image2"]["tmp_name"],"upload/".$_FILES["image2"]["name"]);
        copy($_FILES["image3"]["tmp_name"],"upload/".$_FILES["image3"]["name"]);
        echo "Stored in: " . "upload/" . $_FILES["image1"]["name"];
        echo "<br>";
        echo "Stored in: " . "upload/" . $_FILES["image2"]["name"];
        echo "<br>";
        echo "Stored in: " . "upload/" . $_FILES["image3"]["name"];
    }
?>
<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>demo</title>
   </head>
   <body>
      <form method="post" enctype="multipart/form-data"> 
         image 1 : <input type="file" name="image1" ><br/>
         image 2 : <input type="file" name="image2" ><br/>
         image 3 : <input type="file" name="image3" ><br/>
         <input type="submit" name="submit" value="Submit">
      </form>
   </body>
</html>

iphone screenshot

As we can see from this below array this is displayed in iphone/ipad the image names are same for all and when i try to check for upload folder it displayed only the last image i.e third image .

[image1] => Array
    (
        [name] => image.jpg
        [type] => image/jpeg
        [tmp_name] => /tmp/phpewhdwx
        [error] => 0
        [size] => 44009
    )

[image2] => Array
    (
        [name] => image.jpg
        [type] => image/jpeg
        [tmp_name] => /tmp/phpwYDYBM
        [error] => 0
        [size] => 27762
    )

[image3] => Array
    (
        [name] => image.jpg
        [type] => image/jpeg
        [tmp_name] => /tmp/php0vqnB2
        [error] => 0
        [size] => 32961
    )
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
481 views
Welcome To Ask or Share your Answers For Others

1 Answer

Ok i have found the solution :)

we have issue in ipad's and iphone's as they use name for all images as image.jpg so if we use multiple image this gets overridden so we need to add rand() or any unique key to the name at time of copy to folder.

$image1 = rand().$_FILES["image1"]["name"];
    $image2 = rand().$_FILES["image2"]["name"];
    $image3 = rand().$_FILES["image3"]["name"];

    copy($_FILES["image1"]["tmp_name"],"upload/".$image1);
    copy($_FILES["image2"]["tmp_name"],"upload/".$image2);
    copy($_FILES["image3"]["tmp_name"],"upload/".$image3);  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...