SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help upload 3 images from 1

    Hello all,

    I have a few functions to upload images and create a thumbnail from that image. Now I am trying to add another function to create a third image that I am calling fullsize - For some reason I cant seem to get it to recognize the third img??

    PHP Code:
    function uploadProductImage($inputName$uploadDir)
    {
        
    $image         $_FILES[$inputName];
        
    $ItemId        = (int)$_GET['ItemId'];
        
    $imagePath     '';
        
    $thumbnailPath '';
        
    $fullsizePath '';
        
        
    // if a file is given
        
    if (trim($image['tmp_name']) != '') {
            
    $ext substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']];

            // generate a new file name to avoid name conflict - this is where I want to add ls
            
    $q "SELECT b.Code FROM item i, brands b WHERE i.ItemId = $ItemId AND i.BrandId = b. BrandId";
            
    $result mysql_query($q);
            
    $row mysql_fetch_assoc($result);
            
    extract($row);
            
            
    $imagePath $Code."-".$ItemId."ls" ".$ext";
            
            list(
    $width$height$type$attr) = getimagesize($image['tmp_name']);

            
    // make sure the image width does not exceed the
            // maximum allowed width
            
    if ($width 120) {
                
    $result    createThumbnail($image['tmp_name'], $uploadDir $imagePath120);
                
    //$fsresult     = createFullsize($image['tmp_name'], $uploadDir . $imagePath, 350);
                
    $imagePath $result;
                
    //$fullsizePath = $fsresult;
            
    } else {
                
    $result move_uploaded_file($image['tmp_name'], $uploadDir $imagePath);
            }    
            
            if (
    $result) {
                
    // create thumbnail
                
    $thumbnailPath $Code."-".$ItemId."tn" ".$ext";
                
    $result createThumbnail($uploadDir $imagePath$uploadDir $thumbnailPath96);
                
                
    // if create thumbnail failed, delete the image
                
    if (!$result) {
                    
    unlink($uploadDir $imagePath);
                    
    $imagePath $thumbnailPath $fullsizePath '';
                } else {
                    
    $thumbnailPath $result;
                    
    $fullsizePath $fsresult;
                }    
            } else {
                
    // the product cannot be upload / resized
                
    $imagePath $thumbnailPath $fullsizePath '';
            }
            if (!
    fsresult) {
              
    // create fullsize
                
    $fullsizePath  $Code."-".$ItemId."fs" "$ext";
                
    $result createFullsize($uploadDir $imagePath$uploadDir $fullsizePath350);
                
                
    // if create fullsize failed, delete the image
                
    if (!$result) {
                    
    unlink($uploadDir $imagePath);
                    
    $imagePath $fullsizePath '';
                } else {
                    
    $fullsizePath $result;
                }
            } else {
                
    // the product cannot be upload / resized
                
    $imagePath $thumbnailPath $fullsizePath '';
            }
            
        }

        
        return array(
    'image' => $imagePath'thumbnail' => $thumbnailPath'fullsize' => $fullsizePath);

    This sucessfully creates the ImagelsURL and the ImagetnURL - but no ImagefsURL?
    any ideas what I am doing wrong?

  2. #2
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use this to create a thumbnail and a bigger image

    PHP Code:
    <?php 
    $idir 
    "../images/gallery/full/";   // Path To Images Directory 
    $tdir "../images/gallery/thumbs/";   // Path To Thumbnails Directory 
    $twidth "100";   // Maximum Width For Thumbnail Images 
    $theight "75";   // Maximum Height For Thumbnail Images 
    $ldir "../images/gallery/large/";   // Path To Thumbnails Directory 
    $lwidth "400";   // Maximum Width For Large Images 
    $lheight "300";   // Maximum Height For Large Images



        
    $url $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use 
        
    if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { 
            
    $file_ext strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
            
    $copy copy($_FILES['imagefile']['tmp_name'], "$idir$_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location 
                
    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location 
                   
    print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image 
         
        //insert the image names into the database

        
    include_once "../includes/connection.php";

        
    $query "INSERT INTO image VALUES ('','$pic','$pic','$gallery')";
        
    mysql_query($query);
        
    mysql_close();

        
    $simg imagecreatefromjpeg("$idir$url);   // Make A New Temporary Image To Create The Thumbanil From 
        
    $currwidth imagesx($simg);   // Current Image Width 
        
    $currheight imagesy($simg);   // Current Image Height 
        
    if ($currheight $currwidth) {   // If Height Is Greater Than Width 
            
    $zoom $twidth $currheight;   // Length Ratio For Width 
            
    $newheight $theight;   // Height Is Equal To Max Height 
            
    $newwidth $currwidth $zoom;   // Creates The New Width 
        
    } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) 
            
    $zoom $twidth $currwidth;   // Length Ratio For Height 
            
    $newwidth $twidth;   // Width Is Equal To Max Width 
            
    $newheight $currheight $zoom;   // Creates The New Height 
        

        
    $dimg imagecreate($newwidth$newheight);   // Make New Image For Thumbnail 
        
    imagetruecolortopalette($simgfalse256);   // Create New Color Pallete 
        
    $palsize ImageColorsTotal($simg); 
        for (
    $i 0$i $palsize$i++) {   // Counting Colors In The Image 
            
    $colors ImageColorsForIndex($simg$i);   // Number Of Colors Used 
            
    ImageColorAllocate($dimg$colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use 
        

        
    imagecopyresized($dimg$simg0000$newwidth$newheight$currwidth$currheight);   // Copy Resized Image To The New Image (So We Can Save It) 
        
    imagejpeg($dimg"$tdir$url);   // Saving The Image 
        
    imagedestroy($simg);   // Destroying The Temporary Image 
        
    imagedestroy($dimg);   // Destroying The Other Temporary Image 
        
    print 'Image thumbnail created successfully.';   // Resize successful 
        
    } else { 
            print 
    '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed 
        
    }

        
    $simg imagecreatefromjpeg("$idir$url);   // Make A New Temporary Image To Create The Thumbanil From 
        
    $currwidth imagesx($simg);   // Current Image Width 
        
    $currheight imagesy($simg);   // Current Image Height 
        
    if ($currheight $currwidth) {   // If Height Is Greater Than Width 
            
    $zoom $lwidth $currheight;   // Length Ratio For Width 
            
    $newheight $lheight;   // Height Is Equal To Max Height 
            
    $newwidth $currwidth $zoom;   // Creates The New Width 
        
    } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) 
            
    $zoom $lwidth $currwidth;   // Length Ratio For Height 
            
    $newwidth $lwidth;   // Width Is Equal To Max Width 
            
    $newheight $currheight $zoom;   // Creates The New Height 
        

        
    $dimg imagecreate($newwidth$newheight);   // Make New Image For Thumbnail 
        
    imagetruecolortopalette($simgfalse256);   // Create New Color Pallete 
        
    $palsize ImageColorsTotal($simg); 
        for (
    $i 0$i $palsize$i++) {   // Counting Colors In The Image 
            
    $colors ImageColorsForIndex($simg$i);   // Number Of Colors Used 
            
    ImageColorAllocate($dimg$colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use 
        

        
    imagecopyresized($dimg$simg0000$newwidth$newheight$currwidth$currheight);   // Copy Resized Image To The New Image (So We Can Save It) 
        
    imagejpeg($dimg"$ldir$url);   // Saving The Image 
        
    imagedestroy($simg);   // Destroying The Temporary Image 
        
    imagedestroy($dimg);   // Destroying The Other Temporary Image 
        
    print 'Image thumbnail created successfully.';   // Resize successful 
        
    } else { 
            print 
    '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed 
        


     
    ?>
    There's no reason you can't duplicate the code and change some variables to create another image


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
  •