Beginer : Multi file uploader giving error

Hai folks,

i am trying a simple multi file uploader. but it does not work.
the error shown is : Error Code: Array

<form action="upload.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <p>
   <input type="file" name="adphoto[]" id="adphoto[]" />
 </p>
  <p>
   <input type="file" name="adphoto[]" id="adphoto[]" />
  </p>
  <p>
   <input type="submit" name="button" id="button" value="Submit" />
   <input name="img" type="hidden" id="img" value="submit" />
  </p>
  <p>&nbsp;  </p>
</form>
<?php

if(isset($_POST['img'])){

   $uploaded = 0;
   $message = array();
   foreach ($_FILES['adphoto']['name'] as $i => $name) {
   
        if ($_FILES['adphoto']['error'][$i] == 4) {
            continue; 
        } 
	$file_name = $_FILES['adphoto']['name'][$i];
        if ($_FILES["adphoto"]["error"][$i] == 0){ 
	
		if ((($_FILES["adphoto"]["type"][$i] == "image/pjpeg") 
		    || ($_FILES["adphoto"]["type"][$i] == "image/jpeg")
		    || ($_FILES["adphoto"]["type"][$i] == "image/png" ))
		    && ($_FILES["adphoto"]["size"][$i] < 768000)){ 
		  
		    $new_file_name=rand(00000,99999) . $file_name;
		    $path= "http://www.sitepoint.com/forums/images/".$new_file_name;
		    move_uploaded_file($_FILES["adphoto"]["tmp_name"][$i],$path);    
		    $uploaded++;
		}else{
		    $message[]= "Only JPEG, GIF, or PNG are allowed and less than 750kb";
		    continue;
		}

	}else{
	   echo "Error Code: " . $_FILES["adphoto"]["error"][$i];
	   continue;
	}
	
    }
    echo $uploaded . ' files uploaded.';
    foreach ($message as $error) {
       echo $error;
   }
}

?>

pls help me:)

Let’s indent a bit better:


<?php

if (isset($_POST['img'])) {

  $uploaded = 0;
  $message = array();
  foreach ($_FILES['adphoto']['name'] as $i => $name) {
   
    if ($_FILES['adphoto']['error'][$i] == 4) {
      continue; 
    } 
    $file_name = $_FILES['adphoto']['name'][$i];
    if ($_FILES["adphoto"]["error"][$i] == 0) { 

      if ((($_FILES["adphoto"]["type"][$i] == "image/pjpeg") 
          || ($_FILES["adphoto"]["type"][$i] == "image/jpeg")
          || ($_FILES["adphoto"]["type"][$i] == "image/png" ))
          && ($_FILES["adphoto"]["size"][$i] < 768000)) { 
        $new_file_name=rand(00000,99999) . $file_name;
        $path= "http://www.sitepoint.com/forums/images/".$new_file_name;
        move_uploaded_file($_FILES["adphoto"]["tmp_name"][$i],$path);    
        $uploaded++;
      } else {
        $message[]= "Only JPEG, GIF, or PNG are allowed and less than 750kb";
        continue;
      }
    } else {
      echo "Error Code: " . $_FILES["adphoto"]["error"][$i];
      continue;
    }
  }
  echo $uploaded . ' files uploaded.';
  foreach ($message as $error) {
     echo $error;
  }
}
?>

So this line

echo "Error Code: " . $_FILES["adphoto"]["error"][$i];

gives you the error Error Code: Array ?

That means that $_FILES[“adphoto”][“error”][$i] contains an array.
Try doing a print_r($_FILES[“adphoto”][“error”][$i]);

Thank you so much guido2004 :slight_smile:
i did what you sad. but i only see that same error. nothing else.
so i got a doubt that print_r is not executing. to make sure that i put another echo under the print_r line. the echo also does not shown, so i noticed that the script to which the form is submitted (action) is not what i intended to :rofl: . the form should submit to the document itself.
by mistake the script name in the form’s action attribte is of another :smiley:
now i replaced the correct one and the files are uploading :smiley:
any way, you suggession is what helped to shoot the bug :slight_smile: