Your IP : 18.218.29.253
<?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);
}
}