PHP list contents of directory


 

PHP list contents of directory

This section of the PHP tutorial describes how to display the contents of the given directory. In the example we the use of readir() and opendir()to display the contents of the directory.

This section of the PHP tutorial describes how to display the contents of the given directory. In the example we the use of readir() and opendir()to display the contents of the directory.

  • Contents of a directory or a folder can be displayed one by one.
  • readdir() function returns the directory as well as file name.
  • readdir() takes input as opendir() handle.On success returns the String


Example of PHP List Constents of Directory
<?php
$file
=opendir("c:\apache-ant-1.7.1-bin");
for
(;$a=readdir($file);){
echo
$a."<br>";
}
?>

Output:

..
bin
docs
etc
fetch.xml
get-m2.xml
INSTALL
KEYS
lib
LICENSE
NOTICE
README
WHATSNEW

Ads