Posted By

fackz on 03/09/09


Tagged

list dir files


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

fackz
BrianCoyDesign


list all files in a directory


 / Published in: PHP
 

The .jpg extension can be changed to any extension. So if you want to pull out only .txt files, you just need to replace the .jpg with .txt. If you want to list ALL files, just remove the condition.

  1. //path to directory to scan
  2. $directory = "../images/team/harry/";
  3.  
  4. //get all image files with a .jpg extension.
  5. $images = glob("" . $directory . "*.jpg");
  6.  
  7. //print each file name
  8. foreach($images as $image)
  9. {
  10. echo $image;
  11. }

Report this snippet  

You need to login to post a comment.