这里亚去,希望它有助于:
<?php
/**
* Recursive function that will check all folders in the
* requested directory for keywords [$lookfor] [Any extention]
* true,false on returning notfounds
*
* @param $path to folder
* @param $lookfor word in filename or folder
* @param $showNotfounds [true|false]
* @return echo'ed out
*/
function lookfor($path,$lookfor,$showNotfounds=false){
if(file_exists($path) && is_readable($path)){}else{die('Error reading folder ./'.$path.'');}
if ($handle = @opendir($path)) {
while ($file = readdir($handle)){
if ($file=='.' || $file=='..'){}else{
if (is_dir($path."/".$file)){
//Recursive
if(stristr($file, $lookfor) === FALSE) {
//[folder]missing
echo ($showNotfounds==true) ? '<font color="red"><b>'.$path.'/'.$file.'</b></font>: Not a '.$lookfor.'<br/>': '';
}else{
//[folder]exists
echo '<font color="green"><b>'.$path.'/'.$file.'</b></font>: Is a '.$lookfor.'<br/>';
}
lookfor($path."/".$file,$lookfor,$showNotfounds);
}else{
if(stristr($file, $lookfor) === FALSE) {
//[file]missing
echo ($showNotfounds==true) ? '<font color="red"><b>'.$path.'/'.$file.'</b></font>: Not a '.$lookfor.'<br/>': '';
}else{
//[file]exists
echo '<font color="green"><b>'.$path.'/'.$file.'</b></font>: Is a '.$lookfor.'<br/>';
}
}
}
}
closedir($handle);
}
}
//example usage
lookfor('.','folder.',true);
echo '<hr>';
lookfor('.','poster.',true);
echo '<hr>';
lookfor('.','poster.jpg',false);
?>
http://stackoverflow.com/search?q=folder+php+image的[正则表达式帮助 – Gordon 2011-05-22 21:17:23
可能重复:匹配任何图像文件与开始下划线](http://stackoverflow.com/questions/2139627/regex-help-match-any-image-file-beginning-with-an-underscore) – Gordon 2011-05-22 21:18:43
可能重复的[读取文件夹中的文件](http:///stackoverflow.com/questions/3563863/read-files-in-folder/3564311#3564311) – Gordon 2011-05-22 21:22:28