Posted By


mattkenefick on 10/28/10

Tagged


Statistics


Viewed 524 times
Favorited by 1 user(s)

match_files_in_directory


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.