public static function clearTemp() { try { $tempPath = Base_Constant_Server::getFirstTemp(); if (!is_dir($tempPath)) { return; } $dirIterator = new RecursiveDirectoryIterator($tempPath); $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $path) { switch (true) { case '.' == basename($path->__toString()): case '..' == basename($path->__toString()): case '...' == basename($path->__toString()): break; case $path->isDir(): rmdir($path->__toString()); break; default: unlink($path->__toString()); break; } } } catch (Exception $e) { throw $e; } }