summaryrefslogtreecommitdiffstats
path: root/functions.files.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'functions.files.inc.php')
-rw-r--r--functions.files.inc.php31
1 files changed, 31 insertions, 0 deletions
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);
+}
+?>