Jump to content

PHP Directory Index


nyyankeefan95

Recommended Posts

Hello i am new to php and i was wondering if someone knew how to do this. I just need a simple index.php file that lists the files and folders in a directory but i need it to look exactly like this (With Bullets):

capturevs.png

 

Thank You In Advance

 

(I also need it to open the folder directory if a folder is clicked on and button for Parent Directory)

Link to comment
https://forums.phpfreaks.com/topic/218250-php-directory-index/
Share on other sites

Using the readdir() function you should be able to loop through a directory (the current directory) and list out files.

You can test if it's a file by using an is_file() test.

Try it out. Here's a quick example (untested):

<?php

if($files = readdir('.'))
{
    while(($file = readdir($handle)) !== false)
    {
        echo "<a href='" . $file . "'>" . $file . "</a>";
    }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/218250-php-directory-index/#findComment-1132858
Share on other sites

I have this code which i want to keep:

<?php

if ($handle = opendir('.')) {

  echo "<ul>";

    while (false !== ($file = readdir($handle))) {

        if ($file != "." && $file != "..") {

            echo "<li>$file</li>";

        }

    }

  echo "</ul>";

    closedir($handle);

}

?>

 

but i want to add "Index of/" at the top of the page and i want the text to be able to be clicked on to open the file/folder?

Link to comment
https://forums.phpfreaks.com/topic/218250-php-directory-index/#findComment-1132867
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.