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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.