note 113479 deleted from function.getimagesizefromstring by cmb

From: Date: Fri, 15 Jul 2016 16:30:43 +0000
Subject: note 113479 deleted from function.getimagesizefromstring by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206027@lists.php.net to get a copy of this message
Note Submitter: josh at karmabunny dot com dot au ---- 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

« previous php.notes (#206027) next »