summaryrefslogtreecommitdiffstats
path: root/application/controllers/file.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-02-19 17:49:00 +0100
committerFlorian Pritz <bluewind@xinu.at>2012-02-19 17:49:00 +0100
commitf5bc76ce2fd240325ffc2d0a5e71a27231de2149 (patch)
tree77d975f15472f0e9baec18b89f85fc8701e87875 /application/controllers/file.php
parentccb038f92a2d4fdc4510151e549d83121522ecae (diff)
file/cron: clean up stale files
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers/file.php')
-rw-r--r--application/controllers/file.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index f578dd7c7..c83805600 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -281,6 +281,39 @@ class File extends CI_Controller {
}
}
}
+
+ /* remove files without database entries */
+ // TODO: put into a function
+ $upload_path = $this->config->item("upload_path");
+ $outer_dh = opendir($upload_path);
+
+ while (($dir = readdir($outer_dh)) !== false) {
+ if (!is_dir($upload_path."/".$dir) || $dir == ".." || $dir == ".") {
+ continue;
+ }
+
+ $dh = opendir($upload_path."/".$dir);
+
+ $empty = true;
+
+ while (($file = readdir($dh)) !== false) {
+ if ($file == ".." || $file == ".") {
+ continue;
+ }
+
+ $query = $this->db->query("SELECT hash FROM files WHERE hash = ? LIMIT 1", array($file))->row_array();
+
+ if (empty($query)) {
+ unlink($upload_path."/".$dir."/".$file);
+ } else {
+ $empty = false;
+ }
+ }
+
+ if ($empty) {
+ rmdir($upload_path."/".$dir);
+ }
+ }
}
}