Web Analytics Made Easy -
StatCounter do/do not replace a picture via upload - CodingForum

Announcement

Collapse
No announcement yet.

do/do not replace a picture via upload

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • do/do not replace a picture via upload

    I'm trying to set up this image upload utility to generate thumbnails and optimize the original also. That all works, but I messed up somewhere when I'm naming the file. I want to have the option of writing over a file, or simply creating a new file that appears after all of the files that already existed. However, if I do not specify a file to write over, it writes over the first image. Below are relevant portions of my code (which I am adapting from http://www.ajquick.com/programming/t.../thumbnail.txt), I would greatly appreciate any help.

    PHP Code:
    <?php

    if ($img != ""){
    $nw=250;
    $nh=250;

    $ipath "/home/bduncan/public_html/images";
    $tpath "/home/bduncan/public_html/images";

    $dimensions GetImageSize($img);

    if (
    $replace=="no"){
        
    $picnum="1";
        while (
    is_file("$ipath/$img_type$picnum.jpg")){($picnum=$picnum+1);}
    }

    $biname "$tpath/$img_type$picnum.jpg";
    $thname "$tpath/$img_type$picnum-t.jpg";

    $w=$dimensions[0];
    $h=$dimensions[1];

    $img2 ImageCreateFromJpeg($img);
    $thumb=ImageCreateTrueColor($nw,$nh);

    if ((
    $w>$h) AND ($w>1024)){
        
    $max_width="1024";
        
    $bi_width=$max_width;
        
    $bi_height=(int)(($max_width*$h)/$w);
        
    $bigimg=ImageCreateTrueColor($bi_width,$bi_height);
        
    ImageCopyResampled($bigimg,$img2,0,0,0,0,$bi_width,$bi_height,$w,$h);
        
    ImageJPEG($bigimg,$biname,75);
    }

    elseif ((
    $h >= $w) AND ($h>1024)){
        
    $max_height="1024";
        
    $bi_height=$max_height;
        
    $bi_width=(int)(($max_height*$w)/$h);
        
    $bigimg=ImageCreateTrueColor($bi_width,$bi_height);
        
    ImageCopyResampled($bigimg,$img2,0,0,0,0,$bi_width,$bi_height,$w,$h);
        
    ImageJPEG($bigimg,$biname,75);
    }

    else{
        
    $bigimg=ImageCreateTrueColor($w,$h);
        
    ImageCopyResampled($bigimg,$img2,0,0,0,0,$w,$h,$w,$h);
        
    ImageJPEG($bigimg,$biname,75);
    }

    $wm $w/$nw;
    $hm $h/$nh;

    $h_height $nh/2;
    $w_height $nw/2;

    if(
    $w $h){
        
        
    $adjusted_width $w $hm;
        
    $half_width $adjusted_width 2;
        
    $int_width $half_width $w_height;
        
        
    ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); 
        
    ImageJPEG($thumb,$thname,75); 
        
    }elseif((
    $w $h) || ($w == $h)){
        
        
    $adjusted_height $h $wm;
        
    $half_height $adjusted_height 2;
        
    $int_height $half_height $h_height;
        
        
    ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); 
        
    ImageJPEG($thumb,$thname,75); 

    }else{

        
    ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h);     
        
    ImageJPEG($thumb,$thname,75); 

    }

    imagedestroy($img2);

    }

    ?>

    <form method="post" action="upload.php" enctype="multipart/form-data" name="form2">
      <input type="hidden" name="MAX_FILE_SIZE" value="5000000">
      <span style="font-size: 90%">Image type:</span><br>
       <select name="img_type">
        <option value="photo">Photography
        <option value="sketch">Sketches
        <option value="artwork">Art Work
       </select><br><br>
      <span style="font-size: 90%">Replace an image?</span><br>
       <input type="radio" name="replace" value="yes">Yes<br>
       <input type="radio" name="replace" value="no" checked>No<br><br>
      <span style="font-size: 90%">If yes, which number?</span><br>
       <input type="text" name="picnum" size="3" maxlength="3"><br><br>
      <span style="font-size: 90%">Locate your image:</span><br>
       <input name="img" type="file" id="img"><br>
       <input name="upload" type="submit" value="Upload Image">
     </form>
    </div>
    Last edited by BroChris; Feb 20, 2004, 02:12 PM.
    designsbychris.com

  • #2
    Nevermind, I figured it out. I was missing a $ for the path variable. The code is updated though, and is a working example of an upload script that produces thumbnails also. I hope it is useful to somebody!
    designsbychris.com

    Comment

    Working...
    X