0

ファイル ツリー コードで提供される標準の 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:ここからの元のソース

4

1 に答える 1

1

jQuery File Tree には詳しくありませんが、問題の鍵はループ内にあると思います。

あなたがする必要がある唯一のことは、表示したくないフォルダー/ファイルの名前を持つ配列であるブラックリストを作成することです.

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

次に、ループ内にチェックを実装して、ファイル/フォルダー名がブラックリスト内のものと一致する場合に名前をスキップするようにします (大文字と小文字を区別します)。

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

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

それは基本的にあなたがする必要があることです。正規表現とpreg_match関数を使用して、より柔軟にすることもできます..

于 2013-05-30T16:23:02.837 に答える