php遍历目录viewDir函数

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

<?php
/**
* 遍历目录,找出目录下某个后缀名的所有文件
* */
function viewDir ($directory, $ext) {
if (is_dir($directory)) {
$handle = opendir($directory);
while ($file = readdir($handle)){
$subdir = $directory . '/' .$file;
if ($file != '.' && $file !='..' && is_dir($subdir)){
viewDir($subdir,$ext);
} else if( $file != '.' && $file != '..') {
$fileInfo = pathinfo($subdir);
$fileExt = $fileInfo['extension'];
if ($fileExt == $ext){
echo $directory.'/'.$file.'<br />';
}
}
}
closedir($handle);
}
}
viewDir('E:\www\test','php');
?>

相关文章

PHP中遍历数组的三种常用方法实例分析

PHP中遍历数组的三种常用方法实例分析

本文实例讲述了PHP中遍历数组的三种常用方法。分享给大家供大家参考,具体如下: 在PHP中操作最多的数据估计也就是数组了,有着效率高、速度快、存储方便的特点。 PHP中遍历数组有三种常用...

php实现图片文件与下载文件防盗链的方法

本文实例讲述了php实现图片文件与下载文件防盗链的方法。分享给大家供大家参考。具体分析如下: 在php中最简单的防盗链办法就是利用php的$_SERVER['HTTP_REFERER']...

两个开源的Php输出Excel文件类

1.php-excel php-excel is a very simple library for generating excel documents from php on-the...

php中将字符串转为HTML的实体引用的一个类

复制代码 代码如下:class HtmlEncode {         static $_convertToHtm...

php mssql 日期出现中文字符的解决方法

比如:2005-12-23 读出以后页面会显示为:2005 十二月 23 ,这样给程序处理带来很多不便。查找了一些资料发现是php.ini默认了日期处理功能。 解决方法为: 第一个方法:...