Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Bengal313's Avatar
    Join Date
    Jun 2002
    Location
    Metro Detroit
    Posts
    298
    Thanks
    8
    Thanked 0 Times in 0 Posts

    How to make links using folder content?

    I have a php page that takes in a list of files (image files) from a directory and lists them. I wanted to know is there a way for me to create links using this list? Here is my code.


    <?php
    $dir = "testimages/";

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
    while (($file = readdir($dh)) !== false) {
    print "$file";
    print "<br>";
    }
    closedir($dh);
    }
    }
    ?>
    Last edited by Bengal313; 12-12-2003 at 09:14 PM.
    "Knowledge Speaks But Wisdom Listens"

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Try changing
    PHP Code:
    print "$file"
    to
    PHP Code:
    print "<a href=\"" $file "\">" $file "</a>"

  • #3
    Regular Coder Bengal313's Avatar
    Join Date
    Jun 2002
    Location
    Metro Detroit
    Posts
    298
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thank you very much for that fast response! One currently I am accessing a folder that is in a sub directory, "/testimages". How would I access a folder that is on the same server (SUSE) but is four levels above the php page directory? I tried using ../, but didn't work.
    Last edited by Bengal313; 12-12-2003 at 09:20 PM.
    "Knowledge Speaks But Wisdom Listens"


  •  

    Posting Permissions

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