2012-07-06 76 views
1

我需要将搜索扩展到子文件夹。在子文件夹中搜索

我需要一点点帮助修改和添加功能,这个脚本:

<?php 
if(isset($_GET['s']) and $_GET['s'] != '') { 
    $dir = 'dir/sub-dir'; 
    $ext = '.htm'; 
    $search = $_GET['s']; 
    $results = glob("$dir/*$search*$ext"); 
    if(count($results) != 1) { 
     foreach($results as $item) { 
      echo "<li><a href='$item'>$item</a></li>\r\n";  
     } 
    } 
    if(count($results) == 1) { 
     $item = $results[0]; 
     echo "<li color='blue'><a href='$item'>$item - only result</a></li>\r\n"; 
    } 
    if(count($results) == 0) { 
     echo "<li>no results to display</li>\r\n";  
    } 
} 
else { 
?> 
<form action=''> 
<input name='s'> 
<input type='submit'> 
</form> 
<?php 
} 
?> 

回答

0

我做我的网站在页面类似的东西,我试图用一些新的递归目录列表功能,他们没有为我的申请工作,但他们可能为你。检查此页面。 http://php.net/manual/en/class.recursivedirectoryiterator.php

PHP中还内置了其他类似的函数,该函数链接到该页面上。

对我来说,我用ajax来调用一个围绕scandir()构建的php函数,并将它传递给下一个要列出的文件夹。这很好,因为它总是当前目录的子文件夹。这样我可以使它在嵌套列表中扩展出来。

+0

谢谢约翰,我会尝试设置。 – user1504222 2012-07-06 11:04:08