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
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
Mobile Dev World

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 : Recusively list all files and sub-folders.
Categories : PHP, Filesystem Click here to Update Your Picture
Mark Allsop
Date : Apr 28th 2009
Grade : 5 of 5 (graded 1 times)
Viewed : 3583
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Mark Allsop
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Recusively list all files and sub-folders and show the results on a webpage.
<?php
// ----------------------------------------------------------
// Purpose: Recusively list all files and sub-folders.
// Some original code by mallsop.com on 05/2001.
// Updated by mallsop.com on 04/2009.
// PHP 5 or better. Tested ok on unix hosting box.
// GPL License.
// Some snippets from other php code posted online.
// ----------------------------------------------------------
function scanDirectory($dirid, $dirname, $path, $spaces) {
   
   
// id and full path
   
while (($file = readdir($dirid)) != false) { // loop
   
       
if (($file != ".") && ($file != "..")) { // not these (prevent out of memory error)
           
$dirname_full  = $dirname."/".$file;   
            if (
is_dir($dirname_full) && ($file != "cgi-bin")) { // is a directory and not cgi-bin (of which you may be denied access)
                //echo "[debug $path : $file :$dirname : FOLDER $dirname_full ]<br />\n";
               
                // exclude some dirs here               
               
if ($file != "myhiddenfoldername")  {               
                   
$return .= "$spaces<b>$file</b><br />\n";                                               
                   
$dirid_next = opendir($dirname_full); // was just $file
                   
$newpath = $path."/".$file;
                   
$nextspaces = $spaces."    ";
                   
$return .= scanDirectory($dirid_next, $dirname_full, $newpath, $nextspaces);
                   
$nextspaces = "";
                   
closedir($dirid_next);         
                }
// end folder is ok to show.
                   
               
$dirname_here = "";
                }
            else {   
                 
// isa file, so get the file extension       
                // echo "[debug FILE $dirname_full ]<Br>";               
               
$break = explode(".", $file);
               
$file_ext = $break[1];
               
$file_ext_lowercase = strtolower($file_ext);               
                if ((
$file_ext_lowercase == "swf") OR ($file_ext_lowercase == "php") OR ($file_ext_lowercase == "html")) { // isa file to show
                                                                                           
                   
$return .= "$spaces<a href=\"/$path/$file\">$file</a><br />\n";
                   
                    }
// end isa file to show
               
} // end isa file to check
               
           
} // end not these
           
   
} // end scan loop

return ($return);
}
//end function
?>



Usage
<?php
$results
= ""; // reset
$results .= "<html><head><title>Listfiles by mallsop.com</title></head>\n";
$results .= "<body>\n";
//$results .= "<form method=post action=\"$PHP_SELF\"> \n";
// run script
$spaces = "    ";
$dirname_start = getcwd();
$dirid_start = opendir($dirname_start);
$dirname_here = "".basename($dirname_start);
$results .= "<h3>Listfiles in the $dirname_here folder.</h3>\n";
$results .= scanDirectory($dirid_start, $dirname_start, $dirname_here, $spaces);
closedir($dirid_start);
$results .= "<h3>Finished. Certain files are not shown.</h3>\n";
//$results .= "</form>\n";
$results .= "</body>\n";
$results .= "</html>\n";

// show it all and beer me.
echo $results;

?>



Read a file with strings and create a new file with the first half of each string
Categories : PHP, Strings, Filesystem
Grab images from one or more URLs and save them to a specified local directory.
Categories : PHP, Filesystem, Strings, Arrays
Finds files on your site, uses UNIX find command.
Categories : Complete Programs, Filesystem, PHP
Force file download
Categories : PHP, Filesystem, HTTP, Program Execution
How to find the name of the current file?
Categories : PHP, Filesystem, Strings
Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS
Categories : PHP, Databases, PostgreSQL, Filesystem
Differences between two files
Categories : PHP, Filesystem, Tip
This program implements hot link prevention in php. It is useful for webmasters who do not have access to the server at a level where they can control hot linking can still supply some type of hot link prevention for thier site by using php.
Categories : PHP, Filesystem, Graphics, Content Management
Image Browser
Categories : Filesystem, GD image library, Content Management, PHP
Disk Usage, uses UNIX du command.
Categories : Complete Programs, PHP, Filesystem
PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
Keep() - maintenance function for backup folders
Categories : PHP, Filesystem, Maintenance
Download manager - A PHP script for adding a download page to any site.It also enables you track the no. of downloads.
Categories : PHP, Content Management, Filesystem, Databases, MySQL
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
Remote File Size
Categories : PHP, Filesystem, HTTP, Sockets