summaryrefslogtreecommitdiff
path: root/inc/io.php
diff options
context:
space:
mode:
authorlisps <stummp@loewen.de>2014-02-17 23:15:36 +0100
committerlisps <stummp@loewen.de>2014-02-17 23:15:36 +0100
commitd90a79c0ee1837353622e4b2abb0753ca09dffd2 (patch)
tree554da8dc13606efc2bc1ea7fe3697a5ff87d02e5 /inc/io.php
parentf2643d9ff318af1d2fbb6249e929212381959247 (diff)
parenta83975113c7725a13144b3e65bfb58c8447d37d7 (diff)
downloadrpg-d90a79c0ee1837353622e4b2abb0753ca09dffd2.tar.gz
rpg-d90a79c0ee1837353622e4b2abb0753ca09dffd2.tar.bz2
Merge remote-tracking branch 'origin/diff_navigation' into revisions
Conflicts: inc/parser/xhtml.php
Diffstat (limited to 'inc/io.php')
-rw-r--r--inc/io.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/inc/io.php b/inc/io.php
index eff0279ac..c5225a2e0 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -401,6 +401,56 @@ function io_mkdir_p($target){
}
/**
+ * Recursively delete a directory
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @param string $path
+ * @param bool $removefiles defaults to false which will delete empty directories only
+ * @return bool
+ */
+function io_rmdir($path, $removefiles = false) {
+ if(!is_string($path) || $path == "") return false;
+ if(!file_exists($path)) return true; // it's already gone or was never there, count as success
+
+ if(is_dir($path) && !is_link($path)) {
+ $dirs = array();
+ $files = array();
+
+ if(!$dh = @opendir($path)) return false;
+ while(false !== ($f = readdir($dh))) {
+ if($f == '..' || $f == '.') continue;
+
+ // collect dirs and files first
+ if(is_dir("$path/$f") && !is_link("$path/$f")) {
+ $dirs[] = "$path/$f";
+ } else if($removefiles) {
+ $files[] = "$path/$f";
+ } else {
+ return false; // abort when non empty
+ }
+
+ }
+ closedir($dh);
+
+ // now traverse into directories first
+ foreach($dirs as $dir) {
+ if(!io_rmdir($dir, $removefiles)) return false; // abort on any error
+ }
+
+ // now delete files
+ foreach($files as $file) {
+ if(!@unlink($file)) return false; //abort on any error
+ }
+
+ // remove self
+ return @rmdir($path);
+ } else if($removefiles) {
+ return @unlink($path);
+ }
+ return false;
+}
+
+/**
* Creates a directory using FTP
*
* This is used when the safemode workaround is enabled