List only certain files in a folder with PHP


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

Lists only certain files extensions as links on a page from a defined folder


Copy this code and paste it in your HTML
  1. <?php
  2. //Define directory for files listing
  3. //original example
  4. //$files = glob('/path/to/dir/*.xml');
  5. $files = glob('*.php');
  6. //to limit what is displayed you can use a diff listing:
  7. //$files = array_diff($files, array('index.php','opendb.php'));
  8.  
  9. foreach ($files as $value) {
  10. echo "<a href=http://changetoyoursite/$value>".$value."</a><br>";
  11. }
  12.  
  13.  
  14. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.