Results 1 to 8 of 8

Thread: Script to show folder contents

  1. #1
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Script to show folder contents

    My web host doesn't allow you to view the contents of folders it just gives you this page - http://reddwarf.po.gs/misc/

    Is there a script or such so I can view the contents of my web folders so it looks something like this - http://www.dwarfer.x10hosting.com/stalker/

    Thanks.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    http://www.php.net/manual/en/ref.dir.php
    These php functions should be able to help.

    Some more specifics here--

    From the opendir page -- http://www.php.net/manual/en/function.opendir.php
    PHP Code:
    <?php
    $dir 
    "/etc/php5/";

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
        if (
    $dh opendir($dir)) {
            while ((
    $file readdir($dh)) !== false) {
                echo 
    "filename: $file : filetype: " filetype($dir $file) . "\n";
            }
            
    closedir($dh);
        }
    }
    ?>
    From the readdir page -- http://www.php.net/manual/en/function.readdir.php
    PHP Code:
    <?php
    if ($handle opendir('.')) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
                echo 
    "$file\n";
            }
        }
        
    closedir($handle);
    }
    ?>
    This should point you toward what you're looking for. Using a mix of those functions should allow you to create a nice directory listing script.

    You can even make it layered, so you have the contents of inner folders listed too.

    Decide what you want exactly and then look at those pages to see which functions you should use.


    Note that all of this requires PHP, so you need it installed on your server and enabled (in many/most cases, it is), and your page must be processed by the PHP parser, so it needs to end with .php, not .htm, etc. All of your html will function the exact same way, but this allows for php as well.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you enable read and execute permissions for all on that directory, Apache should generate a listing page like that one.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah........sorry, I'm not sure how to use the PHP script, could you please help me.

    Thanks

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You may just want to try Twey's suggestion.

    Otherwise, lok here--
    http://www.dynamicdrive.com/forums/s...ad.php?p=50943
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks it works great!

  7. #7
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation More optional code

    Sir,

    Thanks for your valuable code. I want this code to be used in such way that it will list folder content on conditional basis. For eg.

    My files names in folder are as listed

    folder name is TEST

    /TEST/12400001.DBF
    /TEST/12400705.DBF
    /TEST/13421201.DBF

    I want those files listed on the basis of their file names. i.e.
    customize view

    1) All files starting with 12 should be listed as for Dated 12 only
    2) All files ending with 400001 with a name GPO, 400705 with name TSO etc.


    My requirement is not to view actual file names but they should be viewed in customized formats.

    Please help and thanks in advance.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Please post the code you're using. This discussion is also 5 years old, so you should start a new one. The code above is just from the php.net manual.

    You should be able to do what you require by using standard "if" statements. But from what you posted, it's unclear where/why you're stuck.

    So please post a new discussion with your code, explaining exactly the details of what is the current problem.

    For now, I'm closing this discussion (because it's 5 years old).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •