your file on the system is ok and the web server will detect the mime type using the file extension and the contents of the file. check the img src tag and be sure the path is a relative path to the web root, and not a filesystem path.
for example if you're sending the file to "/home/httpd/html/images/penguin.jpg" and your web root is "/home/httpd/html/" then in the img src just specify "/images/penguin.jpg" as the file location.
seriously look at storing just the file location in the db and not the contents of the image. there seems to be too many issues with storing the images in the database.
something like the below should also work:
define("GIF", "1");
define("JPG", "2");
define("PNG", "3");
define("SWF", "4");
$temp_image = tempnam ("/tmp", "img");
$fp = fopen($temp_image, "w+");
fwrite($fp,$data);
fclose($fp);
$Image_Info = GetImageSize($temp_image);
if($Image_Info[2] == GIF)
$im = @ImageCreateFromGIF($temp_image); / Attempt to open /
else if($Image_Info[2] == JPG)
$im = @ImageCreateFromJPG($temp_image); / Attempt to open /
else if($Image_Info[2] == PNG)
$im = @ImageCreateFromPNG($temp_image); / Attempt to open /
else
Image_Error("Image Format Not Supported!");
if (!$im) / See if it failed /
echo "Failed To Open Tmp File";
unlink($temp_image);
if($Image_Info[2] == GIF)
ImageGif($im);
else if($Image_Info[2] == JPG)
ImageJPG($im);
else if($Image_Info[2] == PNG)
ImagePNG($im);
else
Image_Error("Image Format Not Supported!");