Posted By

mattkenefick on 10/28/10


Tagged

files match directory Readdir


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mattkenefick


match_files_in_directory


 / Published in: PHP
 

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

  1. function match_files_in_directory($dir, $extension = '.jpg'){
  2. $ary = array();
  3.  
  4. if ($handle = opendir($dir)) {
  5. while (false !== ($file = readdir($handle))) {
  6. if ($file != "." && $file != ".." && strpos($file, $extension) > -1 ) {
  7. $ary[] = $file;
  8. }
  9. }
  10. closedir($handle);
  11. }
  12.  
  13. return $ary;
  14. }

Report this snippet  

You need to login to post a comment.