Edit:
Code was edited to type cast $arg to an array
The thing is, you could have a png or a gif file with a JPG extension...
Using getimagesize(), PHP will lookup the IMAGETYPE constant so that you can be sure that the file is a JPG:
PHP Code:
<?php
function arrCleaner($arg = array())
{
$arg = (array) $arg;
foreach($arg as $eachKey => $eachVal)
{
$type = getimagesize($eachVal);
switch($type[2])
{
case 2:
/* If it's a JPG, do nothing... */
break;
default:
/* Else, unset that value */
unset($arg[$eachKey]);
break;
}
}
return $arg;
}
?>
Usage:
PHP Code:
/* Assume that $myArr contains your list of files */
print_r(@arrCleaner($myArr));
Lookup: http://www.php.net/getimagesize/ if the code doesn't make sense to you :)
Or let me know if you have problems with this function :)