Return to Snippet

Revision: 34766
at October 28, 2010 02:59 by mattkenefick


Initial Code
function match_files_in_directory($dir, $extension = '.jpg'){
    $ary    =   array();

    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && strpos($file, $extension) > -1 ) {
                $ary[]  =   $file;
            }
        }
        closedir($handle);
    }

    return $ary;
}

Initial URL


Initial Description
Returns an array of files that match a search term in a certain directory.

Initial Title
match_files_in_directory

Initial Tags
files, directory

Initial Language
PHP