Hi, I have been experiencing problems uploading PNG and BMP images, However this does not seem to occur with GIF and JPEG images and I cannot tell why. I get the following error message... Warning: imagecreatefrompng() [function.imagecreatefrompng]: 'uploads/USRIMG0000000002-1788589870.png' is not a valid PNG file in /home1/tagomago/public_html/misc/forum/forum_fun.php on line 92 Warning: imagecopyresized() expects parameter 2 to be resource, boolean given in /home1/tagomago/public_html/misc/forum/forum_fun.php on line 102 When I download the files from the server they are black or corrupted. The code I am using is as follows... $imagename = $_FILES['image']['name']; $imagetmp = $_FILES['image']['tmp_name']; $error = $_FILES['image']['error']; $uid = $_SESSION['userid']; if($uid && !$error) { //get extension $pos = stripos($imagename,'.'); if($pos) { $ext = substr($imagename ,$pos+1,strlen($imagename)-$pos-1); if(strncasecmp($ext,'GIF',3)==0 || strncasecmp($ext,'PNG',3)==0 || strncasecmp($ext,'BMP',3)==0 || strncasecmp($ext,'JPG',3)==0 || strncasecmp($ext,'JPEG',4)==0) { $target_path = createfilename($imagename,$uid); if(move_uploaded_file($imagetmp, $target_path)) { //resize image resize($target_path,$ext); //delete existing file $query = "SELECT image FROM users WHERE userid='".$uid."'"; $result = mysql_query($query) or die('Error: ' . mysql_error()); $line = mysql_fetch_array($result,MYSQL_ASSOC); unlink($line['image']); //update image $query = "UPDATE users SET image='".$target_path."' WHERE userid='".$uid."'"; mysql_query($query) or die('Error: ' . mysql_error()); } else{ echo "<script> alert('There was an error uploading the file, please try again!'); </script>"; } } else { echo "<script> alert('This image type is not supported'); </script>"; } } else { echo "<script> alert('This image type is not supported'); </script>"; } } else { echo "<script> alert('There was an error uploading the file, please try again!'); </script>"; } With resize function... function resize($file,$ext) { // get original size list($width, $height) = getimagesize($file); // calc new size $max = max($width,$height); $newwidth = $width*150/$max; $newheight = $height*150/$max; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); if(strcasecmp($ext,'GIF')==0) $source = imagecreatefromgif($file); else if(strcasecmp($ext,'PNG')==0) $source = imagecreatefrompng($file); else if(strcasecmp($ext,'BMP')==0) $source = imagecreatefromwbmp($file); else if(strcasecmp($ext,'JPG')==0) $source = imagecreatefromjpeg($file); else if(strcasecmp($ext,'JPEG')==0) $source = imagecreatefromjpeg($file); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output if(strcasecmp($ext,'GIF')==0) imagegif($thumb,$file); else if(strcasecmp($ext,'PNG')==0) imagepng($thumb,$file); else if(strcasecmp($ext,'BMP')==0) imagewbmp($thumb,$file); else if(strcasecmp($ext,'JPG')==0) imagejpeg($thumb,$file); else if(strcasecmp($ext,'JPEG')==0) imagejpeg($thumb,$file); imagedestroy($thumb); } Any ideas?