Tuesday, March 17, 2009

List of directory contents using array in php

Code
<html>
<body>
<?php
$fileHandler = opendir('C:\Documents and Settings');
while (false !== ($file = readdir($fileHandler))) {
$files[] = $file;
}
sort($files);
print_r($files);
closedir($fileHandler);
?>
</body>
</html>


Output

Array ( [0] => . [1] => .. [2] => A [3] => Administrator [4] => All Users [5] => Default User [6] => LocalService [7] => NetworkService [8] => apache2triad )

Related Documents
Working with cookie in php(set, retrieve, delete)
Accessing data from html forms in php
Track error messages on php
Array declaration, assignment and printing in php
Variables in PHP
Magic constants in php

No comments:

Post a Comment