PHP list directory


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



Copy this code and paste it in your HTML
  1. <?php
  2. $dir = opendir(".");
  3. while($entryName = readdir($dir)){
  4. $dirArray[] = $entryName;
  5. }
  6. closedir($dir);
  7. $indexCount = count($dirArray);
  8. echo $indexCount." Files<br />";
  9. for($index=0; $index < $indexCount; $index++){
  10. if($dirArray[$index] != "." && $dirArray[$index] != ".."){
  11. $type = filetype($dirArray[$index]);
  12. if($type == "dir") {
  13. echo "<img src='img/dir.png'>";
  14. } else {
  15. echo "<img src='img/file.png'>";
  16. }
  17. echo "<a href='".$dirArray[$index]."'>".$dirArray[$index]."</a><br />";
  18. }
  19. }
  20. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.