list all files in a directory


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

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.


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.