note 77481 deleted from function.finfo-file by googleguy

From: Date: Tue, 22 Oct 2013 12:17:51 +0000
Subject: note 77481 deleted from function.finfo-file by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197154@lists.php.net to get a copy of this message
Note Submitter: Ryan Day ---- to check images on unix based systems its much better to use the identify command provided by image magic as it provides accurate results about all files <?php function is_jpg($fullpathtoimage){ if(file_exists($fullpathtoimage)){ exec("identify $fullpathtoimage",$out); //using system() echos STDOUT automatically if(!empty($out)){ //identify returns an empty result to php //if the file is not an image $info = $out[0]; $info = explode(' ',$out[0]); //^IF THE FILENAME CONTAINS SPACES //^THIS WILL NOT WORK...be creative $type = $info[1]; if($type == 'JPEG'){ return true; } } } return false; } ?> identify can process all types of images that are web friendly sample output: ./image/someimage.jpg JPEG 150x112 150x112+0+0 DirectClass 8-bit 4.54688kb if you dont want to control the image name or want to support spaces use: escapeshellarg() http://us2.php.net/manual/en/function.escapeshellarg.php function links: exec() -- http://us2.php.net/manual/en/function.exec.php explode() -- http://us2.php.net/manual/en/function.explode.php

« previous php.notes (#197154) next »