WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 6407
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  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;

?>



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
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
A simple php file uploader
Categories : PHP, Filesystem, HTML and PHP
Open directory and File download
Categories : PHP, Filesystem, Directories, HTML and PHP
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions
Relative Path
Categories : PHP, Filesystem
Upload function using PHP's FTP abilities.
Categories : PHP, Filesystem, FTP
Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem
Functions to read a template file and fill in PHP variables. It will also fill in array variables, displaying parts of the template multiple times.
Categories : PHP, Variables, Filesystem
Massreplace
Categories : Filesystem, Regexps, Strings, PHP
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, 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
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression