note 69817 deleted from function.imagecreatefrompng by colder

From: Date: Fri, 22 Sep 2006 01:36:35 +0000
Subject: note 69817 deleted from function.imagecreatefrompng by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117405@lists.php.net to get a copy of this message
Note Submitter: zdenek dot schee at gmail dot com Reason: bad code ---- This is simple function for uploading images... what it's useful for? Even if the source image is PNG or GIF, the same it will be saved as JPG. <?php uploadimage($HTTP_POST_FILES['userfile'],"path/somejpegfile.jpg"); ?> <?php function uploadimage($user, $destination) { echo "$userfile xxxx $destination"; if($user['name']) { $filename = $user['name']; if (($pos = strrpos($filename, ".")) === FALSE) { //echo "Error - file doesn't have a dot... weird."; } else { $extension = substr($filename, $pos + 1); //echo $extension; // will echo "jpeg" } $lextension = strtolower($extension); echo " $extension"; if(file_exists($destination)) unlink($destination); if(move_uploaded_file($user['tmp_name'], $destination)) echo "&nbsp;success"; else echo "&nbsp;unsucceess"; //chmod("$destination",0777); if(($lextension == "jpg") or ($lextension == "jpeg")) { } elseif($lextension == "gif") { $ima = imagecreatefromgif($destination); unlink($destination); imagejpeg($ima, $destination, 100); } elseif($lextension == "png") { $ima = imagecreatefrompng($destination); unlink($destination); imagejpeg($ima, $destination, 100); } chmod($destination,0777); } } ?>

« previous php.notes (#117405) next »