Results 1 to 2 of 2

Thread: multiple upload and resize

  1. #1
    Join Date
    May 2006
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default multiple upload and resize

    Hye guys i Have tryed it all before posting here ..

    googled and modified existing scripts with no success..


    my goal is to upload multiple images and reseize them...

    i found so many but all single file ..

    can somebody guide me tru this pls..

  2. #2
    Join Date
    May 2006
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok so this is what i have up to know..

    here is the script for single upload that im using uner it i will post what i think

    Code:
    <?php
    
    
    //load the config file
    include("config.php");
    
    //if the for has submittedd
    if (isset($_POST['upForm'])){
    
           $file_type = $_FILES['imgfile']['type'];
           $file_name = $_FILES['imgfile']['name'];
           $file_size = $_FILES['imgfile']['size'];
           $file_tmp = $_FILES['imgfile']['tmp_name'];
    	   $Box = $_POST['Box'];
    	   $CAR_ID = $_GET['ID'];
    
           //check if you have selected a file.
           if(!is_uploaded_file($file_tmp)){
              echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
              exit(); //exit the script and don't do anything else.
           }
           //check file extension
           $ext = strrchr($file_name,'.');
           $ext = strtolower($ext);
           if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
              echo "Wrong file extension.  <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
              exit();
           }
           //get the file extension.
           $getExt = explode ('.', $file_name);
           $file_ext = $getExt[count($getExt)-1];
    
           //create a random file name
           $rand_name = md5(time());
           $rand_name= rand(0,999999999);
           //get the new width variable.
           $ThumbWidth = $img_thumb_width;
    
           //keep image type
           if($file_size){
              if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
                   $new_img = imagecreatefromjpeg($file_tmp);
               }elseif($file_type == "image/x-png" || $file_type == "image/png"){
                   $new_img = imagecreatefrompng($file_tmp);
               }elseif($file_type == "image/gif"){
                   $new_img = imagecreatefromgif($file_tmp);
               }
               //list width and height and keep height ratio.
               list($width, $height) = getimagesize($file_tmp);
               $imgratio=$width/$height;
               if ($imgratio>1){
                  $newwidth = $ThumbWidth;
                  $newheight = $ThumbWidth/$imgratio;
               }else{
                     $newheight = $ThumbWidth;
                     $newwidth = $ThumbWidth*$imgratio;
               }
               //function for resize image.
               if (function_exists(imagecreatetruecolor)){
               $resized_img = imagecreatetruecolor($newwidth,$newheight);
               }else{
                     die("Error: Please make sure you have GD library ver 2+");
               }
               imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
               //save image
               ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
               ImageDestroy ($resized_img);
               ImageDestroy ($new_img);
               //print message
               echo "<br>Image Thumb: <a href=\"$path_thumbs/$rand_name.$file_ext\">$path_thumbs/$rand_name.$file_ext</a>";
            }
    
            //upload the big image
            move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
    
            echo "<br>Image Big: <a href=\"$path_big/$rand_name.$file_ext\">$path_big/$rand_name.$file_ext</a>";
    
            echo "<br><br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
    
    }
    ///////////////////////////insert part added 
    mysql_connect("localhost", "techker_techker", "techker") or die(mysql_error()) ;
    mysql_select_db("techker_iapps") or die(mysql_error()) ;
    
    
    $DateHeure= date("Y-m-d H:i:s");
    
    $query = "INSERT INTO AddOnImages ( CAR_ID, Box , Name, date  )  
    VALUES ( NULL,'$CAR_ID','$Box','$rand_name.$file_ext','$DateHeure')" ;
    mysql_query($query) or die('Error, add album failed : ' . mysql_error());
    
    //$id= mysql_insert_id();
        		//echo "<p>This file has the following Database ID: <b>$id</b>";
    echo "You'll be redirected to Home Page after (4) Seconds";
              echo "<meta http-equiv=Refresh content=4;url=ViewPost.php?ID=>";
    
    
    
    
    
    //print copyright ;)
    echo"
    </body>
    </html>";
    
    ?>
    Ok so in my upload form i have the file field called imagefile
    so basicly i add imagefile2 and 3

    in the uploader

    them im almost shure i need to add this
    $file_type3 = $_FILES['imgfile2']['type'];
    $file_name2 = $_FILES['imgfile2']['name'];
    $file_size2 = $_FILES['imgfile2']['size'];
    $file_tmp2 = $_FILES['imgfile2']['tmp_name'];

    $file_type 3= $_FILES['imgfile3']['type'];
    $file_name 3= $_FILES['imgfile3']['name'];
    $file_size 3= $_FILES['imgfile3']['size'];
    $file_tmp3 = $_FILES['imgfile3']['tmp_name'];


    To get the other images.

    Afther:
    $ext = strrchr($file_name,'.');
    to

    $ext = strrchr($file_name,$file_name2,$file_name3,'.');

    and
    $getExt = explode ('.', $file_name);

    to

    $getExt = explode ('.', $file_name,$file_name2,$file_name3);

    Afther im lost...is this good up to know?

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
  •