here is my code. it does exactly what i want it to do…upload an image and then create a thumbnail. only problem is…when i create the thumbnail. its not so much as a thumbnail as it is a small black picture. because the entire thing is just black. not a smaller version of the picture. any help please?
if ($_FILES['file']['type'] == "image/gif" or $_FILES['file']['type'] == 'image/jpeg' or $_FILES['file']['type'] == 'image/pjpeg'){
$target_path = './data/images/uploads/';
$thumb_path = $target_path."thumbs/";
$target_path = $target_path . basename( $_FILES['file']['name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['file']['name']). " has been uploaded<br>";
} else{
die("There was an error uploading the file, please try again!");
}
} else {
die("File must be an image<br>");
}
createthumb($target_path,$thumb_path.basename( $_FILES['file']['name']),59,59);
the createthumb function:
function createthumb($name,$filename,$new_w,$new_h)
{
$size = getimagesize($name);
$system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
$old_x=$size[0];
$old_y=$size[1];
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;
}
$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);
}