|
Posted by Koncept on 10/13/06 02:56
In article <eg4vg6$48b$1@news.dialog.net.pl>, .:[ ikciu ]:.
<no@mail.com> wrote:
> function findIMG($dir) {
> $files= scandir($dir);
> foreach ($files as $item) {
> if (is_dir($dir.$item) && $item != '.' && $item != '..') {
> findIMG($dir.$item.'/');
> }elseif (file_exists($dir.$item) && !in_array($item, array('.',
> '..'))) { //here you can add extensions
> $fResult[] = $dir.$item;
> }
> }
> }
>
> findIMG('.');
I wrote something similar for another thread...
<?php
/**
* Script to descend a directory looking for images ...
* @return array Array of located images
* @param string (optional) directory to start search in
* @param bool (optional) should the script descend into other
sub-directories
* @param array (void) results array
*/
function findImages($dir=".",$recurse=FALSE,&$a=array()){
if($dh = @opendir($dir)){
while(($item = readdir($dh)) !== false){
if($item != "." && $item != ".." && $item{0} != "."){
if(is_file($curPath=$dir.'/'.$item)){
if(preg_match('/\.(jpe?g|png|gif|tiff?|bmp)$/i',$item))
$a[]=$curPath;
} else {
$recurse && findImages($curPath,$recurse,$a);
}
}
}
closedir($dh);
}
return $a;
}
// call it
printf("<pre>%s</pre>",print_r(findImages(),true));
?>
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
[Back to original message]
|