1. php代码
function file_list($dir, $pattern = "") {
$arr = array();$dir_handle = opendir($dir);
if ($dir_handle) {
while (($file = readdir($dir_handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
$tmp = realpath($dir . '/' . $file);
if (preg_match($pattern , $tmp)) { //!is_dir($tmp) &&
$arr[] = $tmp;
}
}
closedir($dir_handle);
}
return $arr;
}
public function actionTest()
{
$k = $_REQUEST['path'];
if (!empty($k))
{
$path = trim($k);
print_r ($this->file_list($path,"#xlsx?$#"));
}
}
2. 访问
http://127.0.0.1/ppma/index.php?r=entry/test&path=F:/new
结果如下:
Array | |
( | |
[0] => F:\new\a - 副本 (2).xls | |
[1] => F:\new\a - 副本 (3).xls | |
[2] => F:\new\a - 副本 (4) - 副本.xlsx | |
[3] => F:\new\a - 副本 (4).xlsx | |
[4] => F:\new\a - 副本 (5) - 副本.xlsx | |
[5] => F:\new\a - 副本 - 副本 (2).xlsx | |
[6] => F:\new\a - 副本 - 副本.xlsx | |
[7] => F:\new\a - 副本.xlsx | |
[8] => F:\new\a.xls | |
) |