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() -- htt
p://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 -- h
ttps://master.php.net/note/delete/77481/integrated
Del: useless -- http
s://master.php.net/note/delete/77481/useless
Del: bad code -- htt
ps://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 -- http
s://master.php.net/note/delete/77481/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/77481
Reject -- https://mast
er.php.net/note/reject/77481
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|