Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
Directory Listing (0 Comments)
Admin: Posted Date: April 4, 2010

Have you ever wanted to list the contents of your directory in a html file or a PHP file? All you have to do is follow these steps listed in this tutorial. Its a great way to list what is in a directly quickly and effectively.

Directory Listing

Have you ever wanted to list the contents of your directory in a html file or a PHP file? All you have to do is follow these steps:

Paste this code below in to notepad or your favourite text editor.

CODE

<?
$path = "/home/sites/httpdocs/the/dir";
$dir_handle = @opendir($path) or die("Sorry <!-- emo-:( --><img src='http://www.talkdevelopment.com/tutmnger/images/emoticons/sad.gif'><!-- emo-close --> we were Unable to open $path");
echo "Listing of $path<BR>";
while (false !== ($file = readdir($handle))) {
echo "<a href=\"$path/$file\">$file</a><br />";
}
closedir($dir_handle);
?>



or you could perhaps list the files information aswell by using:

CODE

<?
$path = "[PATH TO DIR W/ TRAILING SLASH]";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if(!is_dir($file)) {
$filesize = filesize($path.$file);
echo "Name: $file
File Size:[$filesize Bytes]
Download: <a href=[URL TO DIR]$file>Click Here<br>------";
}
}
closedir($dir_handle);
?>


Step 2: save it as a .PHP file and upload it to your server after customizing the directory path at the top to the directory that you wish to display. Feel free to ask us any questions at the forums if you are having trouble.

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: