closedir() function

Open a directory, read contents into variable, cycle through variable content one
item at a time, printing list of files in directory in sequence (as links). Then run closedir
to close directory

Begin PHP output

End PHP output

Using the <pre> tag, we show the code below which produces the results shown below the code. The code you see below is also run "behind the scenes" in PHP

<?
/*
/** print the current directory in unordered list
*/

print("<ul>\n");

/*
/** open directory
*/
$myDirectory = opendir(".");

// Get each entry
while($entryName = readdir($myDirectory)) {

// print("<li>$entryName \n");
   print("<li><a href=\"./$entryName\">$entryName</a> \n");
}

/*
/** Close directory
*/

closedir($myDirectory);
print("</ul>\n");

?>

Back to Bill's PHP