I've got a php script that reads a directory and lists all of the files/sites in link form, and delay pills work, except I am looking to get so that it is recursive to ensure that after i choose another directory it once more uses the script to show the files inside. At this time after i choose a directory it simply would go to the default apache listing....any assistance is appreciated.

Script:

    <?php
$dirname = '/drives/Storage/AppsOSs/';
$webdirname = '/AppsOSs'; // what the directory appears as from the web browser's point of view

$dir = opendir($dirname);
$file_list = '';

while(($file = readdir($dir)) != false) {
if(($file != '.') && ($file != '..')) {
$file_list .= "<a href=\"$webdirname/$file\">$file</a><br/>";
}
}

closedir($dir);
?>

<p>
<?=$file_list?>
</p>

Have a look in the Directory Iterator and also the Recursive Iterator

http://php.internet/manual/en/class.directoryiterator.php

or perhaps the Recursive Directory Iterator

http://world wide web.php.internet/manual/en/class.recursivedirectoryiterator.php

To begin with your code structure looks horrid - unsure in the event that would be a copy factor or what. But because it stands you are developing a connect to your directory instead of calling the script again. Do this:

<?php
$dirname = ( isset($_GET['dir']) ) ? $_GET['dir'] : '/drives/Storage/AppsOSs/';

if( !$dir = opendir($dirname) )
{
    die("Unable to open $dirname");
}

$file_list = "";

while( ($file = readdir($dir)) !== false)
{
    if( ($file != '.') && ($file != '..') )
    {
        if( is_dir($dirname . $file) )
        {
            $file_list .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $dirname . $file . "\">" . $file . "</a><br/>";
        }
        else
        {
            $file_list .= "<a href=\"$dirname/$file\">$file</a><br/>";
        }
    }
}

closedir($dir);
?>

<p>
<?= $file_list; ?>
</p>

You may want to tweak it slightly to utilize the body. Nevertheless the idea is: Whether it's personal files it loads the File path into the browser, whether it's a directory call the script again using the new dirname. You can elaborate further with something similar to this:

<?php
$dirname = ( isset($_GET['dir']) ) ? $_GET['dir'] : '/drives/Storage/AppsOSs/';

if( !$dir = opendir($dirname) )
{
    die("Unable to open $dirname");
}

$dir_arr = array();
$file_arr = array();

while( ($file = readdir($dir)) !== false)
{
    if( ($file != '.') && ($file != '..') )
    {
        if( is_dir($dirname . $file) )
        {
            $dir_arr[] = "<a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $dirname . $file . "\">" . $file . "</a>";
        }
        else
        {
            $file_arr[] = "<a href=\"$dirname/$file\">$file</a>";
        }
    }
}

closedir($dir);

$dir_list = implode("<br/>", $dir_arr);
$file_list = implode("<br/>", $file_arr);
?>

<p>
<?= "<h1>Directories</h1>" . $dir_list . "<h1>Files</h1>" . $file_list; ?>
</p>

With this particular setup all sites is going to be listed first - instead of mixed alphabetically as with the very first example.

Try the RecursiveIterator-Class and also the DirectoryIterator that are shipped through the SPL (Standard PHP Library). It arrives with PHP, to help you see the documentation on php.internet.

Check this out link: