aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 2a6084f8d..3a81372a0 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -2527,4 +2527,58 @@ function get_dirs($directory)
}
return $sub_dirs;
}
+
+/**
+ * recursively delete a directory
+ * @param string $path
+ * @param string $trash_path, try to move the directory to this path if it cannot be delete
+ */
+function deltree($path, $trash_path=null)
+{
+ if (is_dir($path))
+ {
+ $fh = opendir($path);
+ while ($file = readdir($fh))
+ {
+ if ($file != '.' and $file != '..')
+ {
+ $pathfile = $path . '/' . $file;
+ if (is_dir($pathfile))
+ {
+ deltree($pathfile, $trash_path);
+ }
+ else
+ {
+ @unlink($pathfile);
+ }
+ }
+ }
+ closedir($fh);
+
+ if (@rmdir($path))
+ {
+ return true;
+ }
+ elseif (!empty($trash_path))
+ {
+ if (!is_dir($trash_path))
+ {
+ @mkgetdir($trash_path, MKGETDIR_RECURSIVE|MKGETDIR_DIE_ON_ERROR|MKGETDIR_PROTECT_HTACCESS);
+ }
+ while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
+ {
+ if (!is_dir($r))
+ {
+ @rename($path, $r);
+ break;
+ }
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
+
?> \ No newline at end of file