i wonder how i can solve the following problem:
I’m reading a folder on my server and i’m displaying the contents as follows. if there’s an image i’ll print an image, if there’s folder i’ll print a div with a folder icon. i wonder if it’s possible click on one of those subfolders and then display the contents of this folder the exact same way I’m currently displaying the contents of the parent folder. it should work as kind of an endless loop if there are folders inside of folders.
$path = 'files';
if (($retval = scandir($path)) !== false) {
$retval = array_filter($retval, 'filter_files');
shuffle($retval);
}
function filter_files($file) {
return ($file != '.' && $file != '..' && $file != '.DS_Store' && $file != 'Thumbs.db');
}
//loop through shuffled files
foreach ($retval as $value) {
$ext = pathinfo($value, PATHINFO_EXTENSION); //file extension
if ($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "png") {
print "<img class='thumb' src='$path/$value'/>";
} else if ($ext == "") { //must be a folder
print "<div class='thumb folder'><a href=''>link_to_subfolder</a></div>";
} else {
//not supported
}
}
is that even possible?
On your folders where you have the link set a get variable for the folder path, then if that path exists set the load path to it:
In file:
That example is very basic, you need to consider whether the user can view the folder they are requesting. For example, if I knew you just used the code above I could enter the folder path to the default password directory and view the files. You need add some validation in to check.