猿问

Php为子文件夹上的搜索文件添加命令

我有这个脚本很好用,但我需要添加一个命令来搜索所有子文件夹。


示例:我有一个文件夹 data 并且它包含更多其他文件夹......我需要在这个文件夹中搜索文件。


$dir = 'data'; 

$exclude = array('.', '..', '.htaccess'); 

$q = (isset($_GET['q'])) ? strtolower($_GET['q']) : ''; 

$res = opendir($dir); 


while(false !== ($file = readdir($res))) { 

    if(strpos(strtolower($file), $q) !== false &&!in_array($file, $exclude)) { 

        echo "<a href='$dir/$file'>$file</a>"; 

        echo "<br>"; 

    } 


closedir($res); 


冉冉说
浏览 116回答 2
2回答

慕标5832272

您可以使用 scandir() 函数$dir&nbsp; = '/tmp';$file = scandir($dir);print_r($file);
随时随地看视频慕课网APP
我要回答