1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

default directory page in apache

Discussion in 'PHP' started by Joobz, Mar 9, 2007.

  1. #1
    So you know what that default page looks like in apache when you don't have an "index.html" page and all you see is one that says "index of..."?

    I remember seeing a php script somewhere that makes it so you can actually control the look and feel of this page instead of leaving the default directory page.

    Anyone know of some or have created any of your own?
     
    Joobz, Mar 9, 2007 IP
  2. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    With htaccess you can turn off indexes:

    Or specify a page other than index.html to use as the index:

    Is that what you're saying, or you want to have a "fancier" looking page that lists all the files in a directory?
     
    Robert Plank, Mar 9, 2007 IP
  3. chuckd1356

    chuckd1356 Active Member

    Messages:
    770
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    70
    #3
    I think he means listing all the files in a directory.
    function dirList ($directory) 
    {
    
        // create an array to hold directory list
        $results = array();
    
        // create a handler for the directory
        $handler = opendir($directory);
    
        // keep going until all files in directory have been read
        while ($file = readdir($handler)) {
    
            // if $file isn't this directory or its parent, 
            // add it to the results array
            if ($file != '.' && $file != '..')
                $results[] = $file;
        }
    
        // tidy up: close the handler
        closedir($handler);
    
        // done!
        return $results;
    
    }
    Code (markup):
    There's a function to do that! Hope it helps! If you need more help PM me, green rep?
     
    chuckd1356, Mar 10, 2007 IP
    MattEvers likes this.
  4. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I've never really thought to ask for rep.

    Just adding on to what has been posted so far if you have some directories with index.html pages and some without you may need to get slightly complex so set the directory index to your custom file and then in that file check whether a index.html page exists and if it does redirect. If it doesn't then proceed with what chuckd1356 started.
     
    streety, Mar 10, 2007 IP
  5. Joobz

    Joobz Peon

    Messages:
    598
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Exactly...
    I remember coming across a script that did this somewhere. I want to be able to put files into the directory and have it display the files dynamically. Basically, I want the default type of directory listing page without the generic look. Maybe something where I can control the design.
     
    Joobz, Mar 10, 2007 IP
  6. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok, so take that function chuck posted, have a script that lists all the files in the current directory ... $list = dirlist(".") will put an array of every file in the current folder into the $list variable, then you can loop through it like you want. Set the DirectoryIndex in htaccess to point to that script that lists the files and you can make it look any way you like.
     
    Robert Plank, Mar 10, 2007 IP
  7. Joobz

    Joobz Peon

    Messages:
    598
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    OK, would love to but I need some tips on how to integrate the function into index.php. I am not very skilled at php yet as I am only slightly familiar with the basics (variables, includes, etc). Any tips?
     
    Joobz, Mar 10, 2007 IP
  8. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8
    chuckd1356 has set up the most important part of the script. You might also want to access the last access/modified time and size using stat.
     
    streety, Mar 10, 2007 IP
  9. Joobz

    Joobz Peon

    Messages:
    598
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Joobz, Mar 12, 2007 IP
    streety likes this.