Obama '08

               
   

Go Back   Mike Simonds > Salesforce > PHP Snippets

This is a discussion on PHP Directory Listing Script within the PHP Snippets forums, part of the Salesforce category; I had this problem at work that I completely forgot about. I

Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 06-09-2008, 03:37 PM
Administrator
 
Join Date: May 2007
Posts: 246
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike
PHP Directory Listing Script

I had this problem at work that I completely forgot about. I left one of our production servers directory listings available to all who viewed it, which is a complete no-no. So I wrote this small script that you can name whatever you want and place it in any directory and it will link all your scripts. That way you can directly link to the script and get the same view of a file system without showing all your files and folders if you are missing an index page

PHP Code:
<?php


$dirlisting 
directory_display();
sort($dirlisting);

foreach (
$dirlisting as $file)
{
    if (
filetype($file) == 'dir')
    {
        echo 
"<tr>\n<td><img src=\"./images/folder.png\" /></td>\n</tr>\n";
    }
    else
    {
        echo 
"<tr>\n<td><img src=\"./images/file-generic.png\" /></td>\n</tr>\n";
    }
    echo 
"<tr>\n<td>\n<a href=\"$file\">$file</a></td>\n</tr>\n<br />";
}


function 
directory_display()
{

    
$directory opendir(".");

    
//while ($file = readdir($directory))
    
while (false !== ($file readdir($directory)))
    {
        if (
$file != "." && $file != "..")
        {
            
$dirlisting[] = $file;
        }
    }
    
closedir($directory);
    return 
$dirlisting;
}
?>
The two images for the folders are attached to place in an "/image" folder
Attached Images
  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2  
Old 06-09-2008, 05:58 PM
Junior Member
 
Join Date: May 2008
Posts: 7

Nice little script.

FYI, you should always add the following to your .htaccess file so that your directories are never shown by the web server. This only works on Apache, but that's what most use.

Options -Indexes
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 06-10-2008, 06:11 AM
Administrator
 
Join Date: May 2007
Posts: 246
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Your correct Scott about the addition to your .htaccess, but in my case, our Sysadmins will not turn .htaccess on
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
directory listing, php directory

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump



Powered by vBulletin


SEO by vBSEO 3.2.0 RC8 ©2008, Crawlability, Inc.

1 2 3 4 5