Results 1 to 6 of 6

Thread: Give me script for Multiple Image uploading on single page

  1. #1
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Give me script for Multiple Image uploading on single page

    I want script for multiple Image uploading on a single page.

  2. #2
    Join Date
    Dec 2010
    Location
    Hyderabad, India
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    HTML and PHP cannot do what you are asking for. You either need to develop a Flash based or Java based additional applet program to achieve multiple images select from your image upload popup.

    However, things being always tricky and solvable, we could have more than one "file" type input element for the form which can allow us to upload more than one image from a form.

    Code:
    <input type="file" name="image1" />&nbsp; Image 1<br />
    <input type="file" name="image2" />&nbsp; Image 2<br />
    <input type="file" name="image3" />&nbsp; Image 3... and so on
    
    
    now PHP
    
    <?php
    
    $im1 = $_FILES['image1']['name'];
    $im2 = $_FILES['image2']['name'];
    $im3 = $_FILES['image3']['name'];
    
    ?>
    I suppose you have enough PHP knowledge to do the rest of the stuff. If not, I will try providing all code.

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    http://code.google.com/p/swfupload/ Can handle multiple file uploads in a single upload button click if you want something else please be more specific.
    Corrections to my coding/thoughts welcome.

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    You can use html and php to upload multiple images. Sorry, but I am being a little lazy in not pruning the code to only do what you want. Basically, the second file will test the file to see that what was uploaded is indeed an image, convert the filename to lowercase, upload the original image(s) to the folder you have already created named "screenshots" and a thumbnail version to the folder called "thumbs".

    File1

    PHP Code:
    <div align="center"><hr>
    <
    form enctype="multipart/form-data" action="file2.php" method="POST">
    <
    input type="hidden" name="MAX_FILE_SIZE" value="50000000">
    <
    input type="file" name="pix[]" size="60" id ="pix[]"><br>
    <
    input type="file" name="pix[]" size="60" id ="pix[]"><br>
    <
    input type="file" name="pix[]" size="60" id ="pix[]"><br>
    <
    input type="file" name="pix[]" size="60" id ="pix[]"><br>
    <
    input type="file" name="pix[]" size="60" id ="pix[]"><br>
    <
    input type="file" name="pix[]" size="60" id ="pix[]">
    <
    p><input type="submit" name="Upload" value="Upload Picture">
    </
    form>
    </
    div
    file2

    PHP Code:
    <?php
    $loop
    =1;
    print 
    $_FILES['pix']['name'][$loop];
    function 
    or_f($a$b) {
      return 
    $a || $b;
    }

    function 
    file_has_extension($fn$ext) {
      if(
    is_array($ext))
        return 
    array_reduce(array_map(create_function('$a''return file_has_extension(\'' $fn '\', $a);'), $ext), 'or_f'false);
      else
        return 
    stripos($fn'.' strtolower($ext)) === strlen($fn) - strlen($ext) + 1;
    }

    $image_extensions = array(
      
    'png',
      
    'jpg',
      
    'jpeg',
      
    'gif',
      
    'bmp'
    );
      if(!isset(
    $_POST['Upload']))
      {
        include(
    "file1.php");
      }
      else
      {
    $loop="-1";while ($loop<5){$loop++;
    if (
    $_FILES['pix']['name'][$loop]=="") continue;
        if(
    $_FILES['pix']['tmp_name'][$loop] == "none")
        {
          echo 
    "<b>File did not successfully upload. Check the
                file size. File must be less than 500K.<br>"
    ;
          include(
    "picform.php");
          exit();
        }
    if(
    file_has_extension($_FILES['pix']['name'][$loop], $image_extensions))
        {
          echo 
    "<b>File is not a picture. Please try another
                file.</b><br>"
    ;
          include(
    "file1.php");
          exit();
        }
        else
        {
          
    $destination $_FILES['pix']['name'][$loop];
          
    $destination strtolower($destination);
          
    $rest=substr($destination,-3,3);
          
    $temp_file $_FILES['pix']['tmp_name'][$loop];
          
    move_uploaded_file($temp_file,$destination);
          echo 
    "<p><b>The file has successfully uploaded:  echo http://www.mysite.com/images/screenshots/$destination</b>
                
    {$_FILES['pix']['name'][$loop]}
                (
    {$_FILES['pix']['size'][$loop]})</p>";
    $img="http://www.mysite.com/images/screenshots/$destination";

    $img    $destination;
    $width  "300px";
    $height "";


    // Get new dimensions
    list($width1$height1) = getimagesize($img);
    if (
    $width =="") {$j=$height/$height1$width  $width1  $j;}
    if (
    $height=="") {$j=$width/$width1;   $height $height1 $j;}
    $new_width $width;
    $new_height $height;

    // Resample
    $image_p imagecreatetruecolor($width$height);
    if (
    $rest=="png")     {$image imagecreatefrompng($img);}
    elseif (
    $rest=="jpg") {$image imagecreatefromjpeg($img);}
    elseif (
    $rest=="peg") {$image imagecreatefromjpeg($img);}
    elseif (
    $rest=="gif") {$image imagecreatefromgif($img);}
    imagecopyresampled($image_p$image0000$new_width$new_height$width1$height1);

    // Output
    $img=preg_replace('/h.*\//','',$img);
    $img=strtolower($img);
    $dest="../thumbs/$img";
    if     (
    $rest=="gif")imagegif($image_p,$dest);

    elseif (
    $rest=="png")imagepng($image_p,$dest);

    elseif (
    $rest=="peg")imagejpeg($image_p,$dest);

    elseif (
    $rest=="jpg")imagejpeg($image_p,$dest);

        }
      }}
    ?>
    You can add as many images at a time as you want by simply changing the value of ($loop<5) to 6 or higher in the second file and adding more
    <input type="file" name="pix[]" size="60" id ="pix[]"><br>
    lines to the first file. I could modify the second file a little so that there is never a need to modify ($loop<5) at all.
    Last edited by james438; 12-30-2010 at 06:49 AM. Reason: slight rewording.
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thank you Vijay sir,
    I am actually junior developer , but still I have done it, and it is working. .

  6. #6
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks to all. .

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
  •