2017-08-04 1 views
-1

私が間違っていることを理解できないようです。誰かが私にそれに関するアドバイスをくれればいいのかなと思っていました。私はhereのコードを手に入れましたが、私のコードを追加して、その名前をフォルダのファイルに置き換えました。私は自分のサイトにいる誰でもファイルの名前をクリックできるようにしています。それはあなたが見せてくれるリンクとまったく同じです。私はそれを動作させるための方法を得ましたが、それがリンクのようにうまくいかない理由を理解していません。sqlなしのフォルダからの検索ボックス

<!DOCTYPE html> 
<html> 
<head> 
<style> 
* { 
    box-sizing: border-box; 
} 

#myInput { 
    background-image: url('/css/searchicon.png'); 
    background-position: 10px 10px; 
    background-repeat: no-repeat; 
    width: 100%; 
    font-size: 16px; 
    padding: 12px 20px 12px 40px; 
    border: 1px solid #ddd; 
    margin-bottom: 12px; 
} 

#myTable { 
    border-collapse: collapse; 
    width: 100%; 
    border: 1px solid #ddd; 
    font-size: 18px; 
} 

#myTable th, #myTable td { 
    text-align: left; 
    padding: 12px; 
} 

#myTable tr { 
    border-bottom: 1px solid #ddd; 
} 

#myTable tr.header, #myTable tr:hover { 
    background-color: #f1f1f1; 
} 
</style> 
</head> 
<body> 

<h2>My Customers</h2> 

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"> 

<table id="myTable"> 
    <tr class="header"> 
    <th style="width:60%; align:center;">Name</th> 
    </tr> 
    <tr> 
    <?php 
if ($file = opendir('C:/wamp/www/example.com/Library')) { 

    while (false !== ($entry = readdir($file))) { 
     if ($entry != "." && $entry != "..") { 
print "  
<td href='#'><a href='http://qlhc3kppkxushjyg.onion/example.com/Library/$entry'>$entry</br></a></td> 
"; 
     } 
    } 
     closedir($file); 
} 

?> 
    </tr> 
</table> 


<script> 
function myFunction() { 
    var input, filter, table, tr, td, i; 
    input = document.getElementById("myInput"); 
    filter = input.value.toUpperCase(); 
    table = document.getElementById("myTable"); 
    tr = table.getElementsByTagName("tr"); 
    for (i = 0; i < tr.length; i++) { 
    td = tr[i].getElementsByTagName("td")[0]; 
    if (td) { 
     if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { 
     tr[i].style.display = ""; 
     } else { 
     tr[i].style.display = "none"; 
     } 
    }  
    } 
} 
</script> 

</body> 
</html> 
+0

、エラー? – Spectarion

+0

エラーは表示されません。ただし、キーワードを入力するときは、それに一致するすべてのキーワードがポップアップ表示されます。それにもかかわらず、それはそのようには機能しません。私がそこに投稿するリンクは、私が何をしようとしているのかというアイデアです。誰かがアイディアやアドバイスをしているのかどうか疑問に思っていました。それは大変感謝しています。 –

答えて

1

ここにあります。それは正常に動作しています。ちょうど1つの事.. $file = opendir('C:/wamp/www/example.com/Library')のような絶対パスを使わないで、$file = opendir('Library')のような相対パスを使用してください。つまり、現在のディレクトリにというスクリプトがあり、というディレクトリとというディレクトリがあります。には、フィルタリングするすべてのエントリが含まれています。

例のディレクトリ構造:

 

    htdocs/ 
    ├── Library/ 
    │ ├── John.txt 
    │ ├── Scott.txt 
    │ └── Anna.txt 
    └── index.php (this script) 

スクリプト:

問題は何
<!DOCTYPE html> 
<html> 
    <head> 
     <style> 
     * { 
      box-sizing: border-box; 
     } 

     #myInput { 
      background-image: url('/css/searchicon.png'); 
      background-position: 10px 10px; 
      background-repeat: no-repeat; 
      width: 100%; 
      font-size: 16px; 
      padding: 12px 20px 12px 40px; 
      border: 1px solid #ddd; 
      margin-bottom: 12px; 
     } 

     #myTable { 
      border-collapse: collapse; 
      width: 100%; 
      border: 1px solid #ddd; 
      font-size: 18px; 
     } 

     #myTable th, #myTable td { 
      text-align: left; 
      padding: 12px; 
     } 

     #myTable tr { 
      border-bottom: 1px solid #ddd; 
     } 

     #myTable tr.header, #myTable tr:hover { 
      background-color: #f1f1f1; 
     } 
    </style> 
</head> 
    <body> 
     <h2>My Customers</h2> 
     <input type="text" id="myInput" onkeyup="filter()" placeholder="Search for names.." title="Type in a name"> 
     <table id="myTable"> 
      <tr class="header"> 
       <th style="width:60%; align:center;">Name</th> 
      </tr> 
      <?php 
       if ($file = opendir('C:/wamp/www/example.com/Library')) { 
        while (false !== ($entry = readdir($file))) { 
         if ($entry != "." && $entry != "..") { ?> 
          <tr> 
           <td href='#'> 
            <a href='http://qlhc3kppkxushjyg.onion/example.com/Library/<?php echo $entry; ?>'><?php echo $entry; ?></a> 
           </td> 
          </tr> 
         <?php } 
        } 
        closedir($file); 
       } 
      ?> 
     </table> 
     <script> 
      function filter() { 
       var input, filter, table, tr, td, i; 
       input = document.getElementById("myInput"); 
       filter = input.value.toUpperCase(); 
       table = document.getElementById("myTable"); 
       tr = table.getElementsByTagName("tr"); 
       for (i = 0; i < tr.length; i++) { 
        td = tr[i].getElementsByTagName("td")[0]; 
        if (td) { 
         if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { 
          tr[i].style.display = ""; 
         } else { 
          tr[i].style.display = "none"; 
         } 
        }  
       } 
      } 
     </script> 
    </body> 
</html> 
+1

チップのおかげでライブラリからパスを削除してくれてありがとう。 –

関連する問題