Heim  >  Artikel  >  Backend-Entwicklung  >  php visitFile()遍历指定文件夹函数_PHP教程

php visitFile()遍历指定文件夹函数_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:34:00891Durchsuche

注:visitFile()有少量修改

复制代码 代码如下:


// 查看指定文件夹的文件
$fileList = array();
function visitFile($path)
{
global $fileList;
$path = str_replace("\\", "/", $path);
$fdir = dir($path);
while (($file = $fdir->read()) !== false)
{
if($file == '.' || $file == '..'){ continue; }
$pathSub = preg_replace("*/{2,}*", "/", $path."/".$file); // 替换多个反斜杠
$fileList[] = is_dir($pathSub) ? $pathSub."/" : $pathSub;
if(is_dir($pathSub)){ visitFile($pathSub); }
}
$fdir->close();
return $fileList;
}
?>



$path = str_replace("\\", "/", $path);
$path = preg_replace("*/{2,}*", "/", $path);
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn