您的位置 首页 php

PHP 文件搜索类

/*

给定一文件目录和一待查找的文件名,返回该目录下所有该文件的路径数组

使用方法:

$earchFile=new searchFile();

$res=$earchFile->findFile(‘待查找实际路径’, ‘系统编码的文件名’));

$file_url=$res[0];//带实际路径

$file_url=$res[1];……

系统编码的文件名:方便支持中文文件名

*/

class searchFile

{

protected $arr = array();

function findFile($flodername, $filename)

{

if (!is_dir($flodername)) {

return “不是有效目录”;

}

if ($fd = opendir($flodername)) {

while($file = readdir($fd)) {

if ($file != “.” && $file != “..”) {

$newPath = $flodername.’/’.$file;

if (is_dir($newPath)) {

$this->findFile($newPath, $filename);

}

if ($file == $filename) {

$this->arr[] = $newPath;

}

}

}

}

return $this->arr;

}

}

文章来源:智云一二三科技

文章标题:PHP 文件搜索类

文章地址:https://www.zhihuclub.com/148865.shtml

关于作者: 智云科技

热门文章

网站地图