递归文件搜索(PHP) [英] Recursive File Search (PHP)

查看:76
本文介绍了递归文件搜索(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用递归搜索返回指定目录中的文件. 我成功实现了这一点,但是我想添加几行代码,使我可以指定要返回的某些扩展名.

I'm trying to return the files in a specified directory using a recursive search. I successfully achieved this, however I want to add a few lines of code that will allow me to specify certain extensions that I want to be returned.

例如,仅返回目录中的.jpg文件.

For example return only .jpg files in the directory.

这是我的代码,

<?php
$it = new RecursiveDirectoryIterator("L:\folder\folder\folder");
foreach(new RecursiveIteratorIterator($it) as $file) {
echo $file . "<br/> \n";
}
?>

请让我知道可以添加到上述代码中的内容,谢谢

please let me know what I can add to the above code to achieve this, thanks

推荐答案

<?php
$it = new RecursiveDirectoryIterator("L:\folder\folder\folder");
$display = Array ( 'jpeg', 'jpg' );
foreach(new RecursiveIteratorIterator($it) as $file)
{
    if (in_array(strtolower(array_pop(explode('.', $file))), $display))
        echo $file . "<br/> \n";
}
?>

这篇关于递归文件搜索(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆