mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Updated delete method to support recrusive deletes
This commit is contained in:
1 parent
41ecda5ea3
commit
419fabd80a
6 files changed
+103
-7
No files matched your search
@@ -95,10 +95,11 @@ abstract class Device
|
||||
* @see http://php.net/manual/en/function.filesize.php
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $recrusive
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function delete(string $path):bool;
|
||||
abstract public function delete(string $path, bool $recrusive):bool;
|
||||
|
||||
/**
|
||||
* Returns given file path its size.
|
||||
|
||||
@@ -151,12 +151,26 @@ class Local extends Device
|
||||
* @see http://php.net/manual/en/function.filesize.php
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $recrusive
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $path):bool
|
||||
public function delete(string $path, bool $recrusive = false):bool
|
||||
{
|
||||
return unlink($path);
|
||||
if(is_dir($path) && $recrusive) {
|
||||
$files = glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned
|
||||
|
||||
foreach($files as $file) {
|
||||
$this->delete($file);
|
||||
}
|
||||
|
||||
rmdir($path);
|
||||
}
|
||||
elseif(is_file($path)) {
|
||||
return unlink($path);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user