Just finished doing just this.
Because GD no longer supports GIFs - the best way to do this is through the use of image magick.
The function you will want is:
function uploadImage($image, $fileName, $path, $HTTP_POST_FILES)
{
global $REGISTERED_TYPES, $ALLOWED_IMAGE_TYPES;
// image is the name of the control in my form
$type = $HTTP_POST_FILES['image']['type'];
if (in_array($type, $ALLOWED_IMAGE_TYPES))
{
if (!is_uploaded_file($image))
{
throwError("Error moving file $image: File was not sent by a post request",
"common_image.php",
"");
}
// Determing the image type so that image magick can
// convert it correctly
$extension = $REGISTERED_TYPES[$type];
// Use system so that the php engine waits for the image
// to be made before moving on.
system(IMAGE_MAGICK_CONVERT . " $extension:$image PNG:$path" .
"/$fileName" . ".png");
}
else
{
throwError("Invalid File Type - Only Images are allowed",
"common_image.php",
"");
}
}
I am checking that files are 'allowed images' first also:
/**
IMAGE LOOKUP STUFF
/
$ALLOWED_IMAGE_TYPES = array(
"image/gif",
"image/pjpeg",
"image/jpeg",
"image/png"
);
$REGISTERED_TYPES = array(
"image/gif" => "gif",
"image/pjpeg" => "jpg",
"image/jpeg" => "jpg",
"image/png" => "png"
);
//--------------------------------------------------------------
You'll need to get image magick www.imagemagick.org.
Hope that helps
Marc