dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: how to list folders in my web address

  1. #1
    Join Date
    May 2008
    Posts
    298

    how to list folders in my web address

    hello,
    to share some files with friends, i created a directory under my website and uploaded several folders under that directory. each folder contain the files i want to share.

    but when i type the path to the main directory, it says 403 forbidden. how can i automatically list folders under the main directory? and i want them to be clickable so that once they click on the folder name they should be able to see the files under the folder that they clicked.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,633
    One option is to configure your web server to allow directory listings, or you can create a default page (e.g. index.php) to display the directory contents, making use of the glob() function, perhaps.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2012
    Posts
    39
    OK i get the code that let me list all the folders and subfolders with files inside:

    <?php
    $dir = scandir("./");

    echo "<ul>";
    foreach($dir as $v1){
    if($v1 != "." && $v1 != ".."){
    if(is_file("./".$v1)){
    echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."<br />";
    }
    //// si es un directorio se lo recorre ///////
    if(is_dir("./".$v1)){
    echo "<li><strong>". $v1 ."</strong>";

    $dir2 = scandir("./".$v1);

    echo "<ul>";
    foreach($dir2 as $v2){
    if($v2 != "." && $v2 != ".."){
    if(is_file("./".$v1."/".$v2)){
    echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."/". $v2 ."<br />";
    }
    //// si es un nuevo directorio se lo recorre ///////
    if(is_dir("./".$v1."/".$v2)){
    echo "<li><strong>". $v2 ."</strong>";

    $dir3 = scandir("./".$v1."/".$v2);

    echo "<ul>";
    foreach($dir3 as $v3){
    if($v3 != "." && $v3 != ".."){
    if(is_file("./".$v1."/".$v2."/".$v3)){
    echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."/". $v2 ."/". $v3 ."<br />";
    }
    //// si es un nuevo directorio se lo recorre ///////
    if(is_dir("./".$v1."/".$v2."/".$v3)){
    echo "<li><strong>". $v3 ."</strong>";

    $dir4 = scandir("./".$v1."/".$v2."/".$v3);

    echo "<ul>";
    foreach($dir4 as $v4){
    if($v4 != "." && $v4 != ".."){
    if(is_file("./".$v1."/".$v2."/".$v3."/".$v4)){
    echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."/". $v2 ."/". $v3 ."/". $v4 ."<br />";
    }
    //// si es un nuevo directorio se lo recorre ///////
    if(is_dir("./".$v1."/".$v2."/".$v3."/".$v4)){
    echo "<li><strong>". $v4 ."</strong>";
    }
    }
    }
    echo "</ul>";
    }
    }
    }
    echo "</ul>";
    }
    }
    }
    echo "</ul>";
    }
    }
    }
    echo "</ul>";
    ?>

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    also you can search directory index script, there are lots of useful scripts having good features for sharing files,

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles