Your IP : 18.116.40.173


Current Path : /var/www/admin_ftp_12/data/www/httpdocs/local/php_interface/
Upload File :
Current File : /var/www/admin_ftp_12/data/www/httpdocs/local/php_interface/utils.php

<?php
class Utils {
	public static function clearDir($path, $fileName) {
		$resultPath = self::checkDir($path);
		echo 'Start clearing! Dir: ' . $resultPath . '<br>';
		foreach(new DirectoryIterator($resultPath) as $item) {
			if (!$item->isDot() && $item->isFile()) {
				if($item->getFilename() == $fileName) {
					echo "Delete - {$item->getPathname()} <br>";
					unlink($item->getPathname());
				}
			}else if(!$item->isDot() && $item->isDir()) {
				self::clearDir($resultPath . DIRECTORY_SEPARATOR . $item->getFilename(), $fileName);
			}
		}
	}
	
	public static function checkDir($path) {
		if(file_exists($path)) {
			return $path;
		}
		$arrHomeDir = array_diff(explode(DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT']), ['', '.', '..']);
		$arrDir = array_diff(explode(DIRECTORY_SEPARATOR, $path), ['', '.', '..']);
		$arrResultDir = array_merge([''], $arrHomeDir, $arrDir);
		return implode(DIRECTORY_SEPARATOR, $arrResultDir);
	}
}