summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2017-12-28 13:43:46 +0100
committersteckbrief <steckbrief@chefmail.de>2017-12-28 13:43:46 +0100
commit406f05cd56a6b4d8192ea00b15bb9edef68c7331 (patch)
treeaf632f6095ceae5f24b6a8d646d2087df1ab7e6b
parentb28e7e4125cd8ce0f25dbcaaad14a2ef2446cdb2 (diff)
functions for file and directory operations moved from functions.common to functions.files and recursive directory removal addedHEADmaster
-rw-r--r--functions.common.inc.php11
-rw-r--r--functions.files.inc.php31
2 files changed, 31 insertions, 11 deletions
diff --git a/functions.common.inc.php b/functions.common.inc.php
index a9db566..e1d1f10 100644
--- a/functions.common.inc.php
+++ b/functions.common.inc.php
@@ -16,17 +16,6 @@ function generate_uuid() {
);
}
-function getDirectoryContent($path) {
- if (dir_exists($path)) {
- return array_diff(scandir($path), array('..', '.'));
- }
- return [];
-}
-
-function dir_exists($path) {
- return file_exists($path) && is_dir($path);
-}
-
function format_size($size, $precision = 2) {
$sizes = ['bytes', 'Kb', 'Mb', 'Gb', 'Tb'];
$i = 0;
diff --git a/functions.files.inc.php b/functions.files.inc.php
new file mode 100644
index 0000000..4105eeb
--- /dev/null
+++ b/functions.files.inc.php
@@ -0,0 +1,31 @@
+<?php
+function getDirectoryContent($path) {
+ if (dir_exists($path)) {
+ return array_diff(scandir($path), array('..', '.'));
+ }
+ return [];
+}
+
+function dir_exists($path) {
+ return file_exists($path) && is_dir($path);
+}
+
+function rm_dir($path, $recursive = FALSE) {
+ if (!dir_exists($path)) {
+ return TRUE;
+ }
+
+ if ($recursive) {
+ foreach (getDirectoryContent($path) as $item) {
+ $itemPath = $path.DIRECTORY_SEPARATOR.$item;
+ if (dir_exists($itemPath)) {
+ rm_dir($itemPath, $recursive);
+ } else {
+ unlink($itemPath);
+ }
+ }
+ }
+
+ return rmdir($path);
+}
+?>