[PHP]Listing the contents of a directory

Last update on October 31, 2009 05:48 AM by jak58
Published by netty5

[PHP]Listing the contents of a directory






With PHP, the contents of a directory and its subdirectories can be viewed. Here below is a recursive function, allowing you to browse directories and subdirectories and view the files:


function ScanDirectory($Directory){

  $MyDirectory = opendir($Directory) or die('Error');
	while($Entry = @readdir($MyDirectory)) {
		if(is_dir($Directory.'/'.$Entry)&& $Entry != '.' && $Entry != '..') {
                         echo '<ul>'.$Directory;
			ScanDirectory($Directory.'/'.$Entry);
                        echo '</ul>';
		}
		else {
			echo '<li>'.$Entry.'</li>';
                }
	}
  closedir($MyDirectory);
}

ScanDirectory('.');
Best answers for « Listing the contents of a directory » in :
[MS-Dos]List the contents of a directory in a file Show [MS-Dos]List the contents of a directory in a file Intro Explanation Intro It may be convenient to make the listing of one or more directories in a file, to make a catalog of files. Under MS-DOS (or Windows by opening a...
[MSN Messenger] Delete contacts on the red list Show [MSN Messenger] Delete contacts on the red list Procedure Notes Windows Live Messenger does not allow you to remove someone from the red list. Indeed, an undesired contacts will still appear your contact list, the "delete" box is...
Import contacts from Excel to Outlook ShowImport contacts from Excel to Outlook Issue Solution Issue How to import a contact list from Excel to Outlook and having them in a single list of contact , and not as splited items? Solution By using the software Excel 2000 and...
Save/Import your Messenger contacts ShowSave/Import your Messenger contacts Save the list of contacts Import contact list Always make a backup of your contact list, it’s very useful when creating a new account Messenger, or in case of crash account (yes! This can happen)....
[VB6/VBA] The CommonDialog control Show[VB6/VBA] The CommonDialog control The available functions with CommonDialog Getting started An example of a standard module The various functions of control CommonDialog Here is a list of all the available constants,although...
UNIX - Files ShowIntroduction to UNIX files In UNIX systems any element is represented in the form of a file. All files are architectured around a single tree structure where the base, called the root, is written "/". File types UNIX systems define different...
Lists in HTML ShowLists A list is a structured paragraph containing a series of items. HTML defines three types of lists: Ordered lists; Unordered lists; Definition lists. Ordered Lists Container Type of List Visual Effect item...
UNIX Commands ShowTable of the main UNIX commands Unix Commands Description Options ls lists the content of a directory -a Displays all files, including hidden files -I Displays a...