Share on Google+Share on Google+

PHP list contents of directory

Advertisement
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

Advertisements

Posted on: November 2, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.