Directory delete function

This commit is contained in:
Dennis Eichhorn 2015-12-31 18:04:33 +01:00
parent 5365e39fc2
commit 87597e7586

View File

@ -15,6 +15,8 @@
*/ */
namespace phpOMS\System; namespace phpOMS\System;
use phpOMS\Validation\Validator;
/** /**
* Filesystem class. * Filesystem class.
* *
@ -87,8 +89,30 @@ class FileSystem
{ {
} }
public function delete() public static function deletePath($path) : \bool
{ {
$path = realpath($oldPath = $path);
if ($path === false || !is_dir($path) || Validator::startsWith($path, ROOT_PATH)) {
return false;
}
$files = scandir($path);
/* Removing . and .. */
unset($files[1]);
unset($files[0]);
foreach ($files as $file) {
if (is_dir($file)) {
self::deletePath($file);
} else {
unlink($file);
}
}
rmdir($path);
return true;
} }
public function touch() public function touch()