<?php
namespace Home\Controller;
use Think\Controller;
class RecursiveController extends Controller{
/**
* 构造函数
*/
public function __construct()
{
//初始化操作
}
public function index()
{
$dirPath = '/var/www';
//调用处理函数
$this->loopFun( $dirPath );
}
private function loopFun( $dir )
{
//取出文件或者文件夹
$list = scandir( $dir );
foreach( $list as $file )
{
$location_dir = $dir . '/' . $file;
echo $location_dir . '';
//判断是否是文件夹 是就调用自身函数再去进行处理
if( is_dir( $location_dir ) && '.' != $file && '..' != $file )
{
$this->loopFun( $location_dir );
}
}
}
}
Thinkphp --- 实现递归取出文件以及文件夹
最新推荐文章于 2023-04-12 10:16:37 发布