Same as usual. Open up notepad, or another text editor, and save this code as a .php file:
Quote
<html><head>
<style type='text/css'>
#dirlist { background: #ffffff; }
#file { background: #f6f6f6; }
</style>
</head>
<body>
<?php
//write to files before loading them
//needs adding
//function creation
function DirList($dir,$align) {
echo "<table align='$align' width='80%'>";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$link = $dir."/".$file;
$i++;
if(is_dir($dir."/".$file)) {
echo "<tr><td id='dirlist' align='left'> <b>Directory '$link'</b></td></tr>";
echo "<tr><td id='dirlist' align='left'>"; DirList($link,$align); echo "</td></tr>";
continue;
} else {
echo "<tr><td align='left' id='file'> <a href=\"$link\">$link</a> - ".filesize($link)." bytes.</td></tr>";
}
}
}
if($i <= 0) {
echo "<tr><td align='left' id='file'> -- Folder is empty --</td></tr>";
}
closedir($handle);
}
echo "</table>";
}
DirList(".","center");
?>
</body>
</html>
Almost none of it is editable, as it creates a function. No variables are stored in the function that can be used with other purpose - functions return one value only. That value in this case is every single file and directory in the list. I also skinned it a little.
To change the directory you are looking at, you must change this part:
DirList(argument0,argument1);
argument0 - the directory you look at. "." would display every file in the current directory. "./images/" would display all files in the images folder.
argument1 - the alignment of the display on the screen.













Sign In
Register
Help




MultiQuote




