I am using jQuery File Tree to display a directory listing, toghether with the standard PHP connector provided with the File Tree code.
Everything works fine, but I need to filter the listing to avoid the inclusion of hiden files and not desired folders. My skills in PHP or JS doesn't allow me to go futher than pasting here the code, with the hope I can get some extra lines to hide unwanted files according to certain pattern/s.
Thanks!
The HTML code:
<html>
<head>
<link rel="stylesheet" href="../../js/ft/jqueryFileTree.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="../../js/ft/jqueryFileTree.js"></script>
<script type="text/javascript">
function openFile(file) {
window.location = file;
}
$(document).ready (function() {
$('.filetree').fileTree({
root: '../../../est/dir/',
script: '../../js/ft/connectors/jqueryFileTree.php',
function(file) {
window.open(file);
});
});
</script>
</head>
<body>
<div class="filetree"></div>
</body>
</html>
And the PHP code:
<?php
$_POST['dir'] = urldecode($_POST['dir']);
if( file_exists($_POST['dir']) ) {
$files = scandir($_POST['dir']);
natcasesort($files);
if( count($files) > 2 ) { // The 2 accounts for . and ..
echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
// All dirs
foreach( $files as $file ) {
if( file_exists($_POST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($_POST['dir'] . $file) ) {
echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>";
}
}
// All files
foreach( $files as $file ) {
if( file_exists($_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($_POST['dir'] . $file) ) {
$ext = preg_replace('/^.*\./', '', $file);
echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
}
}
echo "</ul>";
}
}
?>
PS: original source comming from here