How to upload gif images
Posted: Thu Jan 22, 2009 4:21 am
hii..i have to upload images in my project and i am using the code given below. This code is working fine if i am uploading .jpeg or .jpg images but wen i upload .GIF images it doesnt work. Please tell me where am i wrong in this code.
Code: Select all
[color=#FF0000][b]$imgPath = basename($_FILES['img']['name']);
$catname = $_POST['category'];
$scatname = $_POST['subcat'];
$name = $_POST['name'];
$subdesc = $_POST['description'];
$display = $_POST['display'];
$filename = rand().$_FILES['img']['name'];
$temporary_name = $_FILES['img']['tmp_name'];
$mimetype = $_FILES['img']['type'];
$filesize = $_FILES['img']['size'];
if($filename!="")
{
switch($mimetype)
{
//case "image/jpg":
case "image/jpg":
case "image/jpeg":
case "image/pjpeg": //IE's weird jpeg MIME type
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/gif":
$i = imagecreatefromgif($temporary_name);
break;
}
/*echo $i;
exit();*/
//Delete the uploaded file
unlink($temporary_name);
//Save a copy of the original
//imagejpeg($i,"../uploadImages/" . $filename,80);
$dest_x = 100;
$dest_y = 100;
//Is the original bigger than the thumbnail dimensions?
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
//Is the width of the original bigger than the height?
if (imagesx($i) >= imagesy($i)) {
$thumb_x = $dest_x;
$thumb_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$thumb_x = imagesx($i)*($dest_y/imagesy($i));
$thumb_y = $dest_y;
}
} else {
//Using the original dimensions
$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}
//Generate a new image at the size of the thumbnail
$thumb = imagecreatetruecolor($thumb_x,$thumb_y);
//Copy the original image data to it using resampling
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));
//Save the thumbnail
imagejpeg($thumb, "../smallimage/" . $filename, 80);
}[/b][/color]