I am trying to upload a pic to a directory and make a thumbnail in of the image in another directory. Then write both names to the database. I have the single image upload working but not the thumbnail.
Here is what I have:
Now I have found a neat little resizing function that I would like to place in this so it does the resizing. My question is where do I place it? I can't get it to work for anything.PHP Code://################# UPLOAD IMAGE TO FOLDER #################
if ($action == "upload")
{
if ($userfile AND $userfile != "none") {
$handle=opendir($full_path);
while (list($key,$val) = each($accepted_types))
if(!in_array($userfile_type, $accepted_types))
{
{$invalidext=true;break;}
}
if ($userfile_size > $maxsize) {echo "ERR: File too large";}
elseif ($invalidext) {echo "ERR: Forbiden file extension";}
else {
$extt = substr($userfile_name, -4, 4);
$spaceless_name = time() . $extt;
$file_and_path = $full_path . $spaceless_name;
$userfile_name = $spaceless_name;
if(move_uploaded_file($userfile, $file_and_path)){
echo "<table width=600 align=center bgcolor=ffffff><tr><td>Your image has been added \"$userfile_name\" .</td></tr></table>";
} else {
echo "File upload failed!";
}
$strDescription = addslashes(nl2br($txtDescription));
$query = "INSERT INTO tbl_Files (description,filename, filesize, filetype, owner, prop_num) values ('$strDescription', '$userfile_name', '$userfile_size', '$userfile_type', '$current_user', '$propnum')";
if (!mysql_query ($query, $link) )
{
die (mysql_error());
}
echo " uploaded succesfully";
}
}
}
Also here is the function:
PHP Code:<?php
function createthumb($userfile_name,$filename,$new_w,$new_h){
____global $gd2;
____$system=explode(".",$userfile_name);
____if (preg_match("/jpg|jpeg/",$system[1])){
________$src_img=imagecreatefromjpeg($userfile_name);
____}
____if (preg_match("/png/",$system[1])){
________$src_img=imagecreatefrompng($userfile_name);
____} ____
$old_x=imageSX($src_img);
____$old_y=imageSY($src_img);
____if ($old_x > $old_y) {
________$thumb_w=$new_w;
________$thumb_h=$old_y*($new_h/$old_x);
____}
____if ($old_x < $old_y) {
________$thumb_w=$old_x*($new_w/$old_y);
________$thumb_h=$new_h;
____}
____if ($old_x == $old_y) {
________$thumb_w=$new_w;
________$thumb_h=$new_h;
____} ___
if ($gd2==""){
________$dst_img=ImageCreate($thumb_w,$thumb_h);
________imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
____}else{
________$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
________imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
____}
____if (preg_match("/png/",$system[1])){
________imagepng($dst_img,$filename);
____} else {
________imagejpeg($dst_img,$filename);
____}
____imagedestroy($dst_img);
____imagedestroy($src_img);
}
?>




Bookmarks