2017-11-22 2 views
0

Ich muss mehrere Bilder hochladen, habe ich 2 Probleme, die erste, die mir nicht erlaubt, 2 oder mehr Dateien hochladen, wenn es vom Handy ist (hier etwas wichtiges, wenn es ist vom Handy musst du die Kamera öffnen und wenn es im PC ist muss es das Fenster der Dateiauswahl anzeigen, das klappt gut, aber mit dem Handy lässt es nur eins, bisher habe ich es nur auf Android mit Crhome versucht) und das zweite Detail ist mit dem ersten Element ist nicht gespeichert und wenn es nur eine Datei ist, weil es auch nicht, es scheint, dass es nicht die Position [0], wenn ich mehr als ein Bild, das erste nicht speichert und die anderen sind korrekt gespeichert. Ich habe es eine Weile versucht und ich sehe das Problem nicht. Anhang die Struktur meiner Dateien: \ Kamera
└───uploads
└───index.php
└───upload.php2 oder mehr Bilder hochladen PHP

index.php:

<html> 
<head> 
    <meta charset="UTF-8"> 
    <title>upload</title> 
</head> 
<body> 
    <form action="upload.php" method="post" multipart="" enctype="multipart/form-data"> 
     <input type="file" name="img[]" accept="image/*" id="capture" capture="camera" multiple > 
     <input type="submit"> 
    </form> 
</body> 
</html> 

Und upload.php:

Antwort

0

Dies funktioniert für mich, Hop dies wird Ihr zweites Problem lösen.

if (isset($_FILES['Gallery']) && is_array($_FILES['Gallery'])) { 
         $errors= array(); 
         foreach($_FILES['Gallery']['tmp_name'] as $key => $tmp_name) { 
         $file_name = $key.$_FILES['Gallery']['name'][$key]; 
         $file_size =$_FILES['Gallery']['size'][$key]; 
         $file_tmp =$_FILES['Gallery']['tmp_name'][$key]; 
         $file_type=$_FILES['Gallery']['type'][$key]; 
         if($file_size > 2097152){ 
          $errors[]='File size must be less than 2 MB'; 
         } 
         if (empty($errors)==true) { 
          if (is_dir('uploads')==false) { 
          mkdir('uploads', 0700);  // Create directory if it does not exist 
          } 

          if (file_exists("uploads/".$file_name)==false) { 
          move_uploaded_file($file_tmp,"uploads/".$file_name); 
          chmod("uploads/".$filename, 0777); 
          $Gallery_Link = "uploads/".$file_name; 
          } else {         // rename the file if another one exist 
          $Gallery_Link = "uploads/".time()."_".$file_name; 
          rename($file_tmp,$Gallery_Link) ; 
          } 

         } else { 
          echo $errors; 
         } 
         } 
        } 
+0

Ihre 'reArrayFiles' sehen falsch aus. 'count ($ file ['name'])' sagt Ihnen nicht, wie viele Dateien hochgeladen wurden. – chiliNUT

+0

gleiches Problem, das erste Bild einen Fehler uu – Alphalapz

+0

count ($ file hatte [ 'name'] funktioniert – Alphalapz