php读取目录下的所有文件

5年以前  |  阅读数:1657 次  |  编程语言:PHP 
<?php
$path = './use';
$result = scanFile($path);
function scanFile($path) {
  global $result;
  $files = scandir($path);
  foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
      if (is_dir($path . '/' . $file)) {
        scanFile($path . '/' . $file);
      } else {
        $result[] = basename($file);
      }
    }
  }
  return $result;
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8