SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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

    Code HTML4Strict:
    <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 Code:
    <?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

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Let's indent a bit better:
    PHP Code:
    <?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
    PHP Code:
    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]);

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    So this line
    PHP Code:
    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
    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 . the form should submit to the document itself.
    by mistake the script name in the form's action attribte is of another
    now i replaced the correct one and the files are uploading
    any way, you suggession is what helped to shoot the bug


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •