From d95425b9bba002fa2817a4e0fa61edf721c88c45 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 7 Jul 2013 11:28:12 +0000 Subject: bug:2898 make some updates methods static + factorize code from plugins, themes & languages git-svn-id: http://piwigo.org/svn/trunk@23821 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'admin/include/functions.php') 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 -- cgit v1.2.3