note 77481 added to function.finfo-file
| From: | RyanDay at osu1 dot php dot net | Date: | Fri, 31 Aug 2007 09:34:00 +0000 |
| Subject: | note 77481 added to function.finfo-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129927@lists.php.net to get a copy of this message | ||
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
----
Server IP: 64.71.164.2
Probable Submitter: 76.80.75.125
----
Manual Page -- http://www.php.net/manual/en/function.finfo-file.php
Edit -- https://master.php.net/note/edit/77481
Del: integrated -- https://master.php.net/note/delete/77481/integrated
Del: useless -- https://master.php.net/note/delete/77481/useless
Del: bad code -- https://master.php.net/note/delete/77481/bad+code
Del: spam -- https://master.php.net/note/delete/77481/spam
Del: non-english -- https://master.php.net/note/delete/77481/non-english
Del: in docs -- https://master.php.net/note/delete/77481/in+docs
Del: other reasons-- https://master.php.net/note/delete/77481
Reject -- https://master.php.net/note/reject/77481
Search -- https://master.php.net/manage/user-notes.php