2013-05-30 94 views
0

我正在使用jQuery文件树来显示目录列表,以及与文件树代码一起提供的标准PHP连接器。隐藏jQuery文件树中的文件和文件夹

一切工作正常,但我需要筛选列表以避免包含隐藏文件和不需要的文件夹。我在PHP或JS中的技能不允许我比在这里粘贴代码更进一步,希望我可以根据特定模式获得一些额外的行来隐藏不需要的文件。

谢谢!

的HTML代码:

<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> 

而且PHP代码:

<?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:原源从here

回答

1

正在添加我不熟悉jQuery的文件树,但我相信,你问题的关键在于循环。

您需要做的唯一的事情就是创建一个黑名单,一个数组,其中包含您不想显示的文件夹/文件的名称。

$blacklist = array('namefile1', 'namefolder1', 'namefile2'); 

,然后实现在循环内进行检查,以便它跳过的名称,如果文件/文件夹名称相匹配一个是黑名单中(区分大小写)内。

foreach($files as $file) 
{ 
    if (in_array($file, $blacklist)) 
     continue; 

    .... the rest of the code ... 
    .... goes here .............. 
} 

这基本上是你需要做的。你也可以使用正则表达式和preg_match函数,使其更加灵活。

+0

这样做的窍门!谢谢! –