WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Directory Viewer, Directory Content Viewer, Directory Structure to HTML. This code will basically create a complete set of HTMLs to let a user navigate through any directory you want. Excellent code for large file sharing pages.
Categories : Directories, Filesystem, PHP Update Picture
Dark Knite
Date : Mar 14th 2000
Grade : 3 of 5 (graded 4 times)
Viewed : 13970
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Dark Knite
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<<<<<<<<<<<<< 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 "Copyright(c) 2000<BR>";
echo "Property of Darkest Knite<BR>";
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) >>>>>>>>>>>>>>

<<<<<<<<<<<<<<<<<<< COMMENTS >>>>>>>>>>>>>>>>>>>>>
If you think this is too hard to follow then there is another simpler version of it somewhere on
this server, you can look for it, it's written by me (Dark Knite).

The security is still not top knotch yet, please be carefull.

Make sure you change all the paths (includeing the ICONS or just disable that feature
completely) make sure you change the $URL_address in the main PHP file, make sure you
change the $local_address in hte main PMP file to the root of your server and MAKE SURE YOU
FOLOW with / at the end. This goes for the wuery aswell.

Be carefull with the . and .. abuses, once you go back up dirs, you cannot download but you
can see, so it's not that big a security threat but it's not exactly the best thing either.

HERE'S THE SYNTAX:

cgi-bin/dirlist.php3?dirname_to_show/and_sub_if_available/

simple as that, everything is relative so make sure that
$local_address/dirname_to_show/and_sub_if_availabe exist and are valid directorys.
also the $url_address and $local_address should represent the same dir.

If you want to see this code at work come to http://130.113.48.245 and if you have any
wquestions e-mail me, if i'm not swamped with engineering stuff, i'll help you out as much as i
can.

<<And yet another piece of code from DARK KNITE >>



Display list of files within current and subdirectories (recursively) showing each file as an anchored link and each directory as a category header.
Categories : Filesystem, Directories, Arrays, PHP
Extended Get File List Function
Categories : PHP, Filesystem, Search, Directories
a file explorer for the web, filesystem php php3 files dirs directories pictures files windows linux system list ls scripts
Categories : PHP, URLs, Directories, Filesystem
grab directory listings into an array the example prints out each subdirectory in the main dir - further work is to be performed on this one
Categories : Filesystem, PHP, Directories, Search, Utilities
A function which places the path and name of all subdirectories into an array
Categories : PHP, Filesystem, Arrays, Directories
PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
List the content of the directory of your webserver where this small PHP Script resides.
Categories : PHP, Filesystem, Directories, CSS
getDirArray(Path,Filter,Sorted): Returns an array of the files in a directory, filtered by regular expression and either sorted or randomized. Good for random pictures and graphics.
Categories : PHP, Filesystem, Directories
Directory viewer, customize how you display the file structure, easy to understand. Found out about PHP 3 days ago, and this is my first prog.
Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP
Listing the 10 most recently updated files in a given dir by using last- modified variable and printing to html with link to the file
Categories : PHP, Directories, Filesystem
Open directory and File download
Categories : PHP, Filesystem, Directories, HTML and PHP
Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML -
Categories : PHP, Directories, FTP, Filesystem, HTML and PHP
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Open a directory - generate a complete form and a select menu with all files in a given directory.
Categories : Directories, Filesystem
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
 Goktug Oguz wrote : 291
This seems a pretty nice code but if you check it out 
from the coders web site you`ll see the Fatal error in 
the code. So, it seems it`s not working.. 

What`s the use of not working code ?!?
 
 Dark Knite wrote : 292
actually the code works better then perfect, however it 
does take a little setting up.
I assumed you wished to learn not take code and then 
use it on your site without actually understanding it. 
I`m sorry if i gave you the impression i was going to 
design websites for you. 

Try going through the code and setting up the variables 
to match your system. 

http://130.113.48.245 is proof that the code works 
flawlessly
 
 lily xie wrote :295
i think this is a very good example to learn php file 
functions. thanks.