Breaking News
Home / Web / PHP / PHP Snippets / How to list files in a directory in PHP?

How to list files in a directory in PHP?

  1. <?php
  2. if ($handle = opendir(‘/path/to/directory’)) {
  3.     echo "Directory handle: $handlen";
  4.     echo "Entries:n";
  5.     /* This is the correct way to loop over the directory. */
  6.     while (false !== ($entry = readdir($handle))) {
  7.         echo "$entryn";
  8.     }
  9.  
  10.     closedir($handle);}
  11. ?>
[pb_builder]

Check Also

How to rename file in PHP?

If you want to rename a file in PHP you can use the rename function. …

Advertisment ad adsense adlogger