diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/controllers/file.php | 33 |
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); + } + } } } |