Get Image files in a directory into a array


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



Copy this code and paste it in your HTML
  1. function listImages($dirname=".") {
  2. $ext = array("jpg", "png", "jpeg", "gif");
  3. $files = array();
  4. if($handle = opendir($dirname)) {
  5. while(false !== ($file = readdir($handle)))
  6. for($i=0;$i<sizeof($ext);$i++)
  7. if(strstr($file, ".".$ext[$i]))
  8. $files[] = $file;
  9.  
  10. closedir($handle);
  11. }
  12. return($files);
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.