Displaying files of subdirectories

Discussion in 'PHP' started by apple, Mar 26, 2008.

  1. #1
    Hey.. I need some help about How can i list files with thin the subdirectories...
    Following code only display the directories.. i want to display subdirectory files too. I dont want to display sub directory files on the index page..in the way that on the index file it shows the list of subdirectories.. and when i click on any subdirectory, it displays the files of that subdirectory. I would appriciate any help..

    <?
    $path = "./";
    $dir_handle = @opendir($path) or die("Unable to open $path");
    while ($file = readdir($dir_handle)) {
    if($file == "." || $file == ".." || $file == "index.php" )
    continue;
    echo "<a href=\"$file\">$file</a><br />";
    }
    closedir($dir_handle);
    ?> 
    PHP:
     
    apple, Mar 26, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    
    $dir = "/blah/blah/";
    
    // 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);
       }
    }
    
    PHP:
    make your $dir dynamic instead of specifying your directory why not

    $dir = $_GET['directory'];

    <a href="<?=?directory=directorylieshere;?>">
     
    bartolay13, Mar 26, 2008 IP