note 81132 deleted from function.imagecreatefromstring by nlopess

From: Date: Fri, 15 Feb 2008 12:42:49 +0000
Subject: note 81132 deleted from function.imagecreatefromstring by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-136171@lists.php.net to get a copy of this message
Note Submitter: geoff at spacevs dot com ---- A good way to check if an uploaded image is actually an image, is to try to load it with imagecreatefromstring, then you can also convert it from whatever formats the server supports to the format you want it in, as imagecreatefrom string auto-detects the image type, or returns false on error. <?PHP $data = file_get_contents($_FILES['image']['tmp_name']); $img = imagecreatefromstring($data); if (!$img) die('Please upload a valid image file'); ob_start(); imagejpeg($img, null, 90); $data = ob_get_clean(); imagedestroy($img); ?> http://code.rabidhost.com - PHP Tutorials

« previous php.notes (#136171) next »