You are here: Re: Find all files in a directory « All PHP « IT news, forums, messages
Re: Find all files in a directory

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация