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
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 : Mirror a directory structure
Categories : Filesystem, PHP Update Picture
John Yaya
Date : Mar 21st 1999
Grade : 1 of 5 (graded 1 times)
Viewed : 3172
File : No file for this code example.
Images : No Images for this code example.
Search : More code by John Yaya
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

# This code will mirror a directory structure (like /home/ftp/pub, the
anonymous ftp dir) that is headed by the topdir.
# The icons it refere to are those provided by the apache server by default.
These, of course, can be switched to
# whatever you wish.
# This is probably not the most elegant way to do this and the ability to
differentiate between file types could probably
# be added, but it does work. Let me know if you have any questions or
comments <yaya@yps.org>
#
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0">
<TR ALIGN="Center" VALIGN="Middle">
<TD ALIGN="Left" VALIGN="Top" WIDTH="5%">
# Change topdir to the name of the top of the directory structure you wish to
mirror
<IMG SRC="/icons/folder.open.gif" BORDER="0">  <FONT FACE="Arial"
SIZE="2"><B><A HREF="files.php3">topdir</A></B></FONT>
</TD>
</TR>
<?
// Change this to the path to the top of the directory structure
$path = "/path/to/topdir";
// Initialize arrays
$darray[0] = "...";
$farray[0] = "...";
// Check to see if script has been called by itself
if (isset($selectdir)) {
// The selectdir variable contains subdirectories of the topdir separated by
//slashes
// Explode out these directories and list them out with "open folder icons"
        if(strstr($selectdir,"/")) {
                $dirarray = explode("/",$selectdir);
        } else {
                $dirarray[0] = $selectdir;
        }
        $dirsize = sizeof($dirarray);
        $i = 0;
        while ($i < $dirsize) {
                echo "<TR ALIGN=\"Center\" VALIGN=\"Middle\">\n";
                echo "<TD ALIGN=\"Left\" VALIGN=\"Top\">\n";
                $j = -1;
                while ($j < $i) {
                        echo "   ";
                        $j++;
                }
                echo "<IMG SRC=\"/icons/folder.open.gif\" BORDER=\"0\">";
                echo "  ";
                echo "<FONT FACE=\"Arial\" SIZE=\"2\"><B><A HREF=
\"files.php3?selectdir=";
                $j = 0;
                while ($j < $i) {
                        echo $dirarray[$j]."/";
                        $j++;
                }
                echo $dirarray[$i];
                echo "\" onMouseover=\"window.status='";
                echo $dirarray[$i];
                echo "'; return true\" onMouseOut=\"window.status=''; return
true\">";
                echo $dirarray[$i];
                echo "</A></B></FONT>\n";
                echo "</TD>\n";
                echo "</TR>\n";
                $i++;
        }
// Append the selectdir variable on to the path we hardcoded above, resulting
// in a full path to the current directory
        $path = $path."/".$selectdir;
}
// Open the directory specified in the path variable and read the resulting
// entries into two arrays
// darray = directories
// farray = all others (files)
$dir=opendir($path);
while ($file=readdir($dir)) {
        if ($file!="." && $file!=".." && $file!="incoming") {
                switch (filetype($path."/".$file)) {
                        case 'dir':
                                $darray[] = $file;
                                break;
                        default:
                                $farray[] = $file;
                                break;
                }
        }
}
closedir($dir);
// Sort the arrays by name
sort($darray);
sort($farray);
// List out the subdirectories of the current directory
$asize = sizeof($darray);
$i = 0;
while ($i < $asize) {
        if ($darray[$i] != "...") {
                echo "<TR ALIGN=\"Center\" VALIGN=\"Middle\">\n";
                echo "<TD ALIGN=\"Left\" VALIGN=\"Top\">\n";
                $j = -1;
                while ($j < $dirsize) {
                        echo "   ";
                        $j++;
                }
                echo "<IMG SRC=\"/icons/dir.gif\" BORDER=\"0\">";
                echo "  ";
                echo "<FONT FACE=\"Arial\" SIZE=\"2\"><B><A HREF=
\"files.php3?selectdir=";
                if (isset($selectdir)){
                        echo $selectdir."/".$darray[$i];
                } else {
                        echo $darray[$i];
                }
                echo "\" onMouseover=\"window.status='";
                echo $darray[$i];
                echo "'; return true\" onMouseOut=\"window.status=''; return
true\">";
                echo $darray[$i];
                echo "</A></B></FONT>\n";
                echo "</TD>\n";
                echo "</TR>\n";
        }
        $i++;
}
// List out the files in the current directory
$asize = sizeof($farray);
$i = 0;
while ($i < $asize) {
        if ($farray[$i] != "...") {
                echo "<TR ALIGN=\"Center\" VALIGN=\"Middle\">\n";
                echo "<TD ALIGN=\"Left\" VALIGN=\"Top\">\n";
                $j = -1;
                while ($j < $dirsize) {
                        echo "   ";
                        $j++;
                }
                echo "<IMG SRC=\"/icons/generic.gif\" BORDER=\"0\">";
                echo "  ";
                echo "<FONT FACE=\"Arial\" SIZE=\"2\"><B><A HREF=
\"ftp://ftp.yps.org/pub/";
                if (isset($selectdir)){
                        echo $selectdir."/".$farray[$i];
                } else {
                        echo $farray[$i];
                }
                echo "\" onMouseover=\"window.status='";
                echo $farray[$i];
                echo "'; return true\" onMouseOut=\"window.status=''; return
true\">";
                echo $farray[$i];
                echo "</A></B></FONT>\n";
                echo "</TD>\n";
                echo "</TR>\n";
        }
        $i++;
}
?>
</TABLE>



Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
The toll booth
Categories : PHP, Java Script, Filesystem
php jump urls...the best way
Categories : PHP, URLs, Filesystem
Simple way to replace a variable value in a .conf (.ini) file using a webbrowser - the first stage of a complete universal configuration editor
Categories : PHP, Regexps, Code Editors, Filesystem
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
File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection.
Categories : Complete Programs, Content Management, Filesystem, PHP
GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions
Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals.
Categories : PHP, Filesystem, Cache, Sockets, HTTP
JSON File Upload
Categories : PHP, AJAX, Filesystem
Get the correct extension and MIME types of an image, even when the filename is incorrect.
Categories : PHP, Filesystem, General SQL
Read DPI value from image with PHP
Categories : PHP, Graphics, Filesystem
Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
Single-file PHP news system with automatic folder structure creation
Categories : PHP, Filesystem, Arrays
Recursive function to move files on a filesystem. It can be minor changed in order to copy recursively.
Categories : PHP, Filesystem, Algorithms
 Richard van der Brugge wrote :81
Do not take this example into production "as is" 
because it is not secure. If a user start adding "../" to 
the selectdir command it can wander across your whole 
drive.