First of all your code structure looks horrid - not sure if that was a copy and paste thing or what. But as it stands you're creating a link to the directory rather than calling the script again. Try 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 need to tweak it slightly to work with your system. However the idea is: If it's a file it loads the File path directly into the browser, if it's a directory call the script again with the new dirname. You could elaborate further with something like 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 setup all directories will be listed first - rather than mixed alphabetically like in the first example.