mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-07 21:18:39 +00:00
Directory delete function
This commit is contained in:
parent
5365e39fc2
commit
87597e7586
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user