Php Programming Code Examples
Php > Complete Programs Code Examples
Directory viewer customize how you display the file structure easy to
Directory viewer customize how you display the file structure easy to
<HTML><HEAD><TITLE>Dir View</TITLE></HEAD>
<BODY BGCOLOR="#000000" TEXT="#aaaaaa" LINK="#888888" VLINK="#444444">
<CENTER><h1>PHP Directory Viewer</h1><HR></CENTER>
<BR>
<table align="center" cellpadding="0">
<tr><TD> </DT><td>File Name</td><td>File Size</td><td>Description</td></tr>
<?php
$temp = getenv( "QUERY_STRING");
$dir_name = "$temp";
if($dir_name == "") $dir_name = ".";
$handle=opendir($dir_name);
while ($file = readdir($handle)) { // Extract dir content
$filelst = "$filelst,$file";// save into string
}
closedir($handle);//
$filelist = explode(",",$filelst); // Brake string up into array
sort($filelist);
// sort the array acendingly, I suggest you make your own sort because this one sux
for ($count=1;$count<count($filelist);$count++) {
print "<TR>";
$filename=$filelist[$count];
$file_path = "$dir_name/$filename";
$filesize = filesize($file_path);
// You can use another function to format this, but you get the idea.
if (is_file($file_path)) {
// fleBLK.gif is a small icon of a file (draw yourself one and use that or use anything you want)
echo "<TD><img src=fleBLK.gif height=20 width=24></TD>";
echo "<TD><A HREF=\" $dir_name/$filename\" > $filename </A></TD>";
echo "<TD>$filesize bytes</TD>";
// I suggest you change "File" to a function returning a better description or remove it
completely (make sure you take them all out though)
echo "<TD>File</TD>";
}
elseif(($filename != ".") && ($filename != "..")) {
// DirBLK.gif is a small icon of a folder (draw yourself one and use that or use anything you
want)
echo "<TD><img src=DirBLK.gif height=20 width=24></TD>";
echo "<TD><A HREF=\"$filename\" > $filename </A></TD>";
echo "<TD> dir </TD>";
// I suggest you change "Directory" to a function returning a better description or remove it
completely (make sure you take them all out though)
echo "<TD>Directory</TD>";
}
print "</TR>";
}
?>
</table>
</BODY>
</HTML>