Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Image Upload (multiple images at once)

    I have this script, which works perfectly:

    PHP Code:
    <?php 

    require("fileupload-class.php"); 

            
    $Referer $_REQUEST['Referer'] ;
        
    $path "Images"
        
    $upload_file_name "userfile" ;
        
    $acceptable_file_types "image/jpeg|image/pjpeg"
        
    $default_extension ""
        
    $mode 2

        if (isset(
    $_REQUEST['submitted'])) { 
                 
            
    $my_uploader = new uploader($_POST['language']); 
            
    $my_uploader->max_filesize(99999999); 
             
            if (
    $my_uploader->upload($upload_file_name$acceptable_file_types$default_extension)) {
                
    $my_uploader->save_file($path$mode);
            }
            
            if (
    $my_uploader->error) {
                echo 
    $my_uploader->error "<br><br>\n";
            
            } else {
                print(
    "Your file: <br>" $my_uploader->file['name'] . " <br>was successfully uploaded!");

                if(
    stristr($my_uploader->file['type'], "image")) {

                } else {
                    
    $fp fopen($path $my_uploader->file['name'], "r");
                    while(!
    feof($fp)) {
                        
    $line fgets($fp255);
                        echo 
    $line;
                    }
                    if (
    $fp) { fclose($fp); }
                }
             }
         }

    ?>
    However i would like to be able to upload multiple images at the same time, by having multiple browse boxes on the form and then simply hitting the upload button should upload all the files selected.

  • #2
    Regular Coder
    Join Date
    Jul 2004
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's possible using files array in a basic html form. Then loop a PHP script.

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    could you please elaborate on that please. (sample code)

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I would do (based on your current script and ease of changing it), is name your form fields like this:

    Code:
    <input type="file" name="files[]" />
    <input type="file" name="files[]" />
    <input type="file" name="files[]" />
    And then you can loop through and run the action on the files, regardless how many submitted...

    PHP Code:
    <?php

    for($i=0;$i<count($_FILES['files']['name']);$i++)
    {
      
    $filename $_FILES['files']['name'][$i];
      
    // Do rest of file upload as required...
    }


  •  

    Posting Permissions

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