I have a php script that reads a directory and lists all the files/directories in link form, and it works, except I'm trying to get it to be recursive so that when I choose another directory it once again uses the script to display the files inside. Right now when I select a directory it just goes to the default apache listing....any help 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>
Take a look at the Directory Iterator and the Recursive Iterator
http://php.net/manual/en/class.directoryiterator.php
or even the Recursive Directory Iterator
http://www.php.net/manual/en/class.recursivedirectoryiterator.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With