Mega Code Archive

 
Categories / Php / File Directory
 

Directory Viewer, Directory Content Viewer, Directory Structure to HTML

< Main PHP FILE (dirlist.php3) > <HTML> <? $url_address = "http://130.113.48.245"; $local_address = "d:/Server"; $relative_address = str_replace( '%20', ' ', $QUERY_STRING ); $listing_title = "In responce to: $local_address/$relative_address"; require "darklib.inc"; heather($listing_title); record_user(); $fp = opendir("$local_address/$relative_address"); while ($file = readdir($fp)) if (filetype($local_address . "/" . $relative_address.$file) == file) { $Ufiles[] = $file; $Lfiles[] = strtolower($file); } else { $Ufolders[] = $file; $Lfolders[] = strtolower($file); } closedir($fp); sort($Lfolders); for ($i=0; $i<=count($Lfolders)-1; $i++) { for ($j=0; $j<=count($Lfolders)-1; $j++) { if (strcmp($Lfolders[$i], strtolower($Ufolders[$j])) == 0) { $folders[] = $Ufolders[$j]; } } } for ($i=0; $i<=count($folders)-1; $i++) $item[] = $folders[$i]; if (count($Lfiles) > 0) { sort($Lfiles); for ($i=0; $i<=count($Lfiles)-1; $i++) { for ($j=0; $j<=count($Lfiles)-1; $j++) { if (strcmp($Lfiles[$i], strtolower($Ufiles[$j])) == 0) { $files[] = $Ufiles[$j]; } } } for ($i=0; $i<=count($files)-1; $i++) $item[] = $files[$i]; } for ($i=0; $i<=count($item)-1; $i++) { if (strcmp($item[$i], "..") != 0 && strcmp($item[$i], ".") != 0) { if (filetype($local_address."/".$relative_address.$item[$i]) == file) { $filesize = number_format(filesize($local_address."/".$relative_address.$item [$i])/1024)." kb"; echo "<TR>"; $icon_file = iconcalc($item[$i]); echo "<TD><A HREF=\"$url_address/$relative_address$item[$i]\"><img src=/Icons/$icon_file height=17 width=16 border=0></A></TD>"; echo "<TD><A HREF=\"$url_address/$relative_address$item[$i]\">$item[$i] </TD>"; echo "<TD>$filesize</TD>"; echo "<TD>File</TD>"; } else { $filesize = "Directory"; echo "<TR>"; echo "<TD><A HREF=\"$url_address/cgi-bin/dirlist.php3?$relative_address$item [$i]/\"><img src=/Icons/dirBLK.gif height=17 width=16 border=0></A></TD>"; echo "<TD><A HREF=\"$url_address/cgi-bin/dirlist.php3?$relative_address$item [$i]/\">$item[$i]</TD>"; echo "<TD></TD>"; echo "<TD>Folder</TD>"; } } } echo "</table>"; echo "<center>"; echo "<HR>"; echo "</center>"; echo "</BODY>"; ?> </HTML> < END OF Main PHP FILE (dirlist.php3) > < THE INCLUDE FILE (darklib.inc) > <? FUNCTION record_user($Referer_IP,$User_IP) { $pathname = "d:/server/test/logs/"; $filename = sprintf("%s%s", $pathname, "referer.txt"); $fp=fopen($filename,"r+"); if ($fp == 0) { print "Error opening file"; } while (!feof($fp)) { fgetc($fp); } fputs($fp,"User $User_IP was sent here by $Referer_IP \n"); fclose($fp); } FUNCTION heather($listing_title) { print "<style TYPE=text/css>"; print "<!--"; print "table {font-size:12px;letter-spacing:0}"; print "a {font-size:12px;letter-spacing:0}"; print "-->"; print "</style>"; print "<BODY vLink=\"#184498\" Link=\"#184498\" aLink=\"#184498\" bgcolor=\"#000000\" text=\"#6595FF\">"; print "<CENTER><div class=\"h1\">Directory Index</div>"; print "<div class=\"h2\">$listing_title</div>"; print "<A HREF=\"javascript:location.reload()\">[Refresh]</A>"; print "<HR></CENTER><BR>"; print "<table align=\"center\" cellpadding=\"0\" nowrap width=\"90%\">"; print " <TR><TD width=\"20\"></TD><TD width=\"*\"><B>File Name</B></TD><TD width=\"50\"><b>Size</b></TD><TD width=\"30\"><b>Type</b></TD></TR>"; print " <TR><TD width=\"20\"><img src=\"/icons/backBLK.gif\" height=17 width=16></TD><TD width=\"*\"><A href=\"javascript:history.back(1);\">[Go Back] </A></TD><TD width=\"10\"></TD><TD width=\"10\"></TD></TR>"; } FUNCTION iconcalc($file_name) { $temp = explode(".", $file_name); if ($temp[count($temp)-1] == "txt" || $temp[count($temp)-1] == "diz" || $temp[count ($temp)-1] == "me" || $temp[count($temp)-1] == "nfo") { return "txtBLK.gif"; } else if ($temp[count($temp)-1] == "gif" || $temp[count($temp)-1] == "jpg" || $temp [count($temp)-1] == "jpeg" || $temp[count($temp)-1] == "bmp" || $temp[count($temp)-1] == "tif"){ return "picBLK.gif"; } else if ($temp[count($temp)-1] == "ace" || $temp[count($temp)-1] == "zip" || $temp [count($temp)-1] == "rar"){ return "aceBLK.gif"; } else if ($temp[count($temp)-1] == "mp3" || $temp[count($temp)-1] == "wav" || $temp [count($temp)-1] == "mp2"){ return "mp3BLK.gif"; } else if ($temp[count($temp)-1] == "doc" || $temp[count($temp)-1] == "xls") { return "docBLK.gif"; } else { return "unknown.gif"; } } ?> < END OF INCLUDE FILE (darklib.inc) >