note 113479 added to function.getimagesizefromstring

From: Date: Thu, 17 Oct 2013 05:25:33 +0000
Subject: note 113479 added to function.getimagesizefromstring
Groups: php.notes 
Request: Send a blank email to php-notes+get-196569@lists.php.net to get a copy of this message
If you need to get the type (but not the size) of an image contained within a string, you can make use of the signatures contained within the headers of various file formats. <?php function get_img_type($data) { $magics = array( 'ffd8ff' => 'jpg', '89504e470d0a1a0a' => 'png', ); foreach ($magics as $str => $ext) { if (strtolower(bin2hex(substr($data, 0, strlen($str)/2))) == $str) return $ext; } return NULL; } ?> If required, additional magic signatures can be added to the array, there is a page on Wikipedia with a good list: http://en.wikipedia.org/wiki/List_of_file_signatures ---- Server IP: 69.147.83.199 Probable Submitter: 203.122.241.231 ---- Manual Page -- http://php.net/manual/en/function.getimagesizefromstring.php Edit -- https://master.php.net/note/edit/113479 Del: integrated -- https://master.php.net/note/delete/113479/integrated Del: useless -- https://master.php.net/note/delete/113479/useless Del: bad code -- https://master.php.net/note/delete/113479/bad+code Del: spam -- https://master.php.net/note/delete/113479/spam Del: non-english -- https://master.php.net/note/delete/113479/non-english Del: in docs -- https://master.php.net/note/delete/113479/in+docs Del: other reasons-- https://master.php.net/note/delete/113479 Reject -- https://master.php.net/note/reject/113479 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196569) next »