PHP SPL SplFileInfo FilterIterator 轮询文件删除

PHP SPL SplFileInfo FilterIterator 轮询文件删除

基于PHP spl 遍历文件删除过期的日志文件

 

一.定义PHP类 , 限制文件扩展 RecursiveFileFilterIterator.class.php 

<?php
class RecursiveFileFilterIterator  extends FilterIterator 
{
	
	protected $ext = array("log","jpg","gif");

	public function __construct($path) {
		parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
	}

	public function accept() {
		$item = $this->getInnerIterator();
		if ($item->isFile() && in_array(pathinfo($item->getFilename(), PATHINFO_EXTENSION), $this->ext)) {
			return TRUE;
		}
	}
}
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » PHP SPL SplFileInfo FilterIterator 轮询文件删除