public function process(FileInfo $path) { if (mb_strlen($path->getPathname()) < 5) { throw new DirectoryCleanerException('For security reasons, path must be at least 5 chars long', DirectoryCleanerException::SecurityLimitation); } if (!$path->exists()) { return; } $worker = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path->getPathname(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($worker as $entry) { if ($entry->isDir() && !$entry->isLink()) { rmdir($entry->getPathname()); } else { unlink($entry->getPathname()); } } rmdir($path); }
public function process(FileInfo $path) { if (mb_strlen($path->getPathname()) < 5) { throw new DirectoryCleanerException('For security reasons, path must be at least 5 chars long', DirectoryCleanerException::SecurityLimitation); } if (!file_exists($path)) { return; } $worker = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path->getPathname())); foreach ($worker as $x) { if ($x->getFilename() == "." || $x->getFilename() == "..") { continue; } if ($x->isDir()) { $this->clearDirectory(new FileInfo($x->getPathname())); } unlink($x->getPathname()); } }
/** * The pathname of the current entry * * @return string */ public function key() { return $this->currentEntry ? $this->currentEntry->getPathname() : null; }