I have created the following "filebrowser" for my upload site.
But now I want to disable the following directories for showing
..
/directory/thumbs
I have the following code (it's working except of the above points) 😉
$directory_name = "uploads/$var_username";
if ($dir = opendir($directory_name )) {
while (($file_name = readdir($dir)) !== false) {
$rel_file = $directory_name . '/' . $file_name; // <---
$extension = substr($rel_file, -4);
$extension = strtolower($extension);
if (is_dir($rel_file)) {
echo "<img src=\"images/folder.gif\"width=\"16\" height=\"16\"> "; echo "<a href=\"index.php? &action=filebrowser&path=$file_name\" target=\"_self\">$file_name<br>\n</a>";
}
if (!is_dir($rel_file)) {
if ($extension == '.jpg') {
echo "<img src=\"images/jpg.gif\" width=\"16\" height=\"16\"> ";
}
if ($extension == '.gif') {
echo "<img src=\"images/gif.gif\" width=\"16\" height=\"16\"> ";
}
if ($extension == '.bmp') {
echo "<img src=\"images/bmp.gif\" width=\"16\" height=\"16\"> ";
}
echo "<b>$file_name</b><br>\n";
}
}
closedir($dir);
}
If I use an IF statement wich checks on the last characters, I can filter, but this doesn't look a nice way to solve / workaround this issue.
$is_2dot = substr($rel_file, -2);
$is_2dot = strtolower($is_2dot); //Checks if it's a [b]..[/b] path
$is_thumbpath = substr($rel_file, -6);
$is_thumbpath = strtolower($is_thumbpath); //Checks if it's a [b]thumbs[/b] path
And then with an IF after if (is_dir($rel_file)) { for not displaying those paths as show below
if (is_dir($rel_file)) {
if ($is_thumbpath != 'thumbs') {
if ($is_2dot != '..') {
echo "<img src=\"images/folder.gif\" width=\"16\"eight=\"16\"> ";
echo "<a href=\"index.php?&action=filebrowser&path=$file_name\"target=\"_self\">$file_name<br>\n</a>";
}
}
}
Someone has a clue ?