note 81132 added to function.imagecreatefromstring

From: Date: Fri, 15 Feb 2008 03:38:18 +0000
Subject: note 81132 added to function.imagecreatefromstring
Groups: php.notes 
Request: Send a blank email to php-notes+get-136165@lists.php.net to get a copy of this message
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 ---- Server IP: 217.174.223.124 Probable Submitter: 58.108.166.70 ---- Manual Page -- http://www.php.net/manual/en/function.imagecreatefromstring.php Edit -- https://master.php.net/note/edit/81132 Del: integrated -- https://master.php.net/note/delete/81132/integrated Del: useless -- https://master.php.net/note/delete/81132/useless Del: bad code -- https://master.php.net/note/delete/81132/bad+code Del: spam -- https://master.php.net/note/delete/81132/spam Del: non-english -- https://master.php.net/note/delete/81132/non-english Del: in docs -- https://master.php.net/note/delete/81132/in+docs Del: other reasons-- https://master.php.net/note/delete/81132 Reject -- https://master.php.net/note/reject/81132 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136165) next »