Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

php - multiple image upload is not working in iphone and ipad

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

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

1 Reply

0 votes
by (71.8m points)

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);  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...