php 读取遍历指定目录下的所有文件

function scanFile($curpath,$找子目录 = true)
{
  $files   = scandir($curpath);
  $fileary = array();
  foreach ($files as $file)
  {
    if ($file != '.' && $file != '..')
    {
      if (is_dir($curpath . '/' . $file) && $找子目录==true)
      {
        $subfileary = scanFile($curpath . '/' . $file,$找子目录);
        $fileary    = array_merge($fileary,$subfileary);
      }
      else
      {
        $fileary[] = $curpath . '/' .basename($file);
      }
    }
  }
  return $fileary;
}
//演示
$firstpath = './images';
$result    = scanFile($firstpath);
//不区分大小写自然排序
natcasesort($result);
$i         = 0;
foreach ($result as $file)
{
  $i++;
  echo $i.'.'.$file.'<br>';
}
点赞