PHP list directories

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandotjoseph
    New Member
    • Mar 2012
    • 2

    PHP list directories

    Hi

    I'm having some trouble making a script to list a given directory at the root of my website.

    Basically this is how I have it set up...

    root//

    photo_upload <-- folder
    proofing <--- PHP file

    I want the proofing php file to LIST the folders inside the photo_upload.

    If anyone could help, that'd be great.

    Current this is the code that I have:
    Code:
    <?php
    
    $dir="photo_upload"; // Directory where files are stored
    
    if ($dir_list = opendir($dir))
    {
    while(($filename = readdir($dir_list)) !== false)
    {
    ?>
    <p><a href="<?php echo $filename; ?>"><?php echo $filename;
    ?></a></p>
    <?php
    }
    closedir($dir_list);
    }
    
    ?>
    Problems with this code is that it lists all the files, and I just want the directories and when I click on the link, it goes to mydomainname.co m/directory name instead of mydomainname.co m/photo_upload/directory.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    why should it go to example.com/photo_upload/directory? you don’t put the $dir directory in the URL of the link.

    Comment

    • chandotjoseph
      New Member
      • Mar 2012
      • 2

      #3
      because the folders i want to list are in photo_upload. so if they click on the links that were generated from the list, they'll go to to it.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        then tell the link to go to that directory. PHP only lists the directory names, not the directory URLs.

        Comment

        Working...