I noticed that Message-ID: <7c************ ********@comcas t.com> from DH
contained the following:
I have a "file upload form" that works OK, but I have been unsuccessful
in my attempt to also resize the uploaded .JPG (if it is too wide),
over-writing the original .JPG, and then create and save a thumbnail.jpg
... all at the same time. Links to a working example would be
appreciated.
I've got some code that needs tidying up, but you are welcome to have a
look.
$thumbpath = "images/thumb/";
$mainpath="imag es/main/";
$max_size = 1000000;
if (!isset($_FILES['userfile'])) exit;
if (is_uploaded_fi le($_FILES['userfile']['tmp_name'])) {
if ($_FILES['userfile']['size']>$max_size)
{ echo "The file is too big<br>\n"; exit; }
if($_FILES['userfile']['type']=="image/gif"){
$createfunction ="imagecreatefr omgif";}
else{$createfun ction="imagecre atefromjpeg";}
if (($_FILES['userfile']['type']=="image/gif") ||
($_FILES['userfile']['type'])=="image/pjpeg" ||
($_FILES['userfile']['type']=="image/jpeg")) {
//check if file already uploaded
//if (file_exists($t humbpath ."s_". $_FILES['userfile']['name'])) { echo
"The file already exists<br>\n"; exit; }
//make a copy of original file
//$res = copy($_FILES['userfile']['tmp_name'], $path .
//$_FILES['userfile']['name']);
//create thumbnail image
$src_img = $createfunction ($_FILES['userfile']['tmp_name']);
$new_w = 120;
$new_h = imagesy($src_im g)/(imagesx($src_i mg)/$new_w);
$dst_img = imagecreatetrue color($new_w,$n ew_h);
imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h,
imagesx($src_im g), imagesy($src_im g));
imagejpeg($dst_ img, $thumbpath ."s_".
$_FILES['userfile']['name'], 100);
//create big image
if(imagesx($src _img)>450){
$new_w = 450;
$new_h = imagesy($src_im g)/(imagesx($src_i mg)/$new_w);
$dst_img = imagecreatetrue color($new_w,$n ew_h);
$res=imagecopyr esampled($dst_i mg, $src_img, 0, 0, 0, 0, $new_w,
$new_h, imagesx($src_im g), imagesy($src_im g));
imagejpeg($dst_ img, $path ."b_".
$_FILES['userfile']['name'], 50);
$notify = "<span class=\"indent1 0bold\">Main image resampled</span>";
}
else{
$res = copy($_FILES['userfile']['tmp_name'], $mainpath
.."b_".$_FILE S['userfile']['name']);
$notify = "<span class=\"indent1 0bold\">Main image not
resampled</span>";
}
if (!$res) { echo "<span class=\"indent1 0bold\">Upload
failed!</span><br>\n"; exit; } else { echo "<span
class=\"indent1 0bold\">Upload sucessful!</span><br><br>\n ";
}
$filename=$_FIL ES['userfile']['name'];
printf("<span class=\"indent1 0bold\">Main :
</span>%sb_%s<br> \n",$path,$file name);
printf("<span class=\"indent1 0bold\">Thumbna il :
</span>%ss_%s<br> \n",$thumbpath, $filename);
//echo "<span class=\"indent1 0bold\">Main File Name:
</span>".$_FILES['userfile']['name']."<br>\n";
echo "<span class=\"indent1 0bold\">Origina l File Size: </span>
".$_FILES['userfile']['size']." bytes<br>\n";
echo "<span class=\"indent1 0bold\">File Type:
</span>".$_FILES['userfile']['type']."<br>\n";
echo "$notify.<br>\n ";
} else { echo "<span class=\"indent1 0bold\">Please use a .jpg or a .gif file</span><br>\n"; exit; }
//printf("<img src=\"%s%s\">", $path,$filename );
//printf("<img src=\"%sb_%s\"a lt=\"%s\">",$pa th,$filename,$m ainurl_alt);
printf("<span class=\"indent1 0bold\">Image Thumbnail:
</span><br><br><s pan class=\"indent1 0bold\"><img
src=\"%ss_%s\"a lt=\"%s\"></span><br>",$thu mbpath,$filenam e,$thumburl_alt );
imagedestroy($s rc_img);
imagedestroy($d st_img);
}
//end of image upload
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs
http://www.ckdog.co.uk/rfdmaker/