有一大堆檔我們如何找到需要的內容呢,這裡實現的方法就是找到對應目錄. 打開目錄. 遍歷所有檔. 每個檔掃一遍, 如果含有顯示出來,沒有繼續查找,直到結束。
分頁檔(allFile.php)
<div id="checkArea">
<h2>Just Check It!</h2>
<form action="check.php" method="post">
Input the folder’s relative path:<br />
<input type="text" name="checkDir" /><br />
Input what you wanna check:<br />
<input type="text" name="checkStr" /><br />
<input type="submit" value="Check!" class="btn" />
</form>
</div>
內容處理檔(check.php)
<?php
//獲取到頁面傳遞的檔路徑, 需要查詢的字串
//去掉字串中的所有空格, 回車, tab縮進
$dir = $_POST["checkDir"];
$check = $_POST["checkStr"];
$check = str_replace(" ","",$check);
$check = str_replace("rn","",$check);
$check = str_replace("t","",$check);
//打開目錄
$dir_handle = openDir($dir);
$date = "";
echo "<table id="allFile">n";
echo "<tr><th class="listNum">Num</th><th>Stauts</th><th class="alignLeft" >File Name</th><th>File Size</th><th>File Type</th><th>Time</th>< /tr>";
$listNum = 0;
while($file = readdir($dir_handle)){
if(filetype($dir.$file) != "dir"){
$listNum++;
echo "<tr><td class="listNum">".$listNum." </td>";
//獲取檔全部內容(字串)
$date = file_get_contents($dir.$file);
//去掉字串中的所有空格, 回車, tab縮進
$date = str_replace(" ","",$date);
$date = str_replace("rn","",$date);
$date = str_replace("t","",$date);
//檢測是否包含有特定字串
if(strstr($date,$check)){
echo "<td><span>√</span></td>";
}else{
echo "<td><span class="red">X</span></td>";
}
$date = "";
//列印結果
echo "<td class="alignLeft"><a href="".$dir.$file."" target="_blank">".$file." </a></td>";
echo "<td>".filesize($dir.$file)." byte</td>";
echo "<td>".filetype($dir.$file)." </td>";
echo "<td>".date("Y-n-t",(filemtime($dir.$file)))." </td>";
echo "</tr>n";
}
}
echo "</table>n</div>";
//關閉目錄
closedir($dir_handle);
?>
樣式表檔就不寫了.. 自己根據需要改一改就好