Version: 1.1

Type: Function

Category: File Management

License: GNU General Public License

Description: Gets all Files starting at a Directory. this function will give you an Array back with all Fileinformation. More Information at http://www.php-resource.de



$file_path = "randompics/"; //dir
$with_subdirs = true; // with subdirs?
$what_file = "/.+\.(gif$|jpg$|jpeg$)/i"; // what file? (reg ex)

$pics = addfiles($file_path,$what_file,$with_subdirs);

echo implode("<br>",$pics);

function addfiles($path,$what_file,$with_subdirs)
{
global $files;
$files[0] = "";
$handle = @opendir($path);
while ($file = @readdir ($handle)) {
    if ($file != "." && $file != ".."){
        if ($with_subdirs) addfiles($path.$file."/",$what_file,$with_subdirs); // subdirs
        if (preg_match($what_file , $file)) $files[] = $path.$file; // addfile
        }
    }
@rewinddir ($handle);
@closedir($handle);
unset ($files[0]);
return $files;
}