From fb01797274be73ac10124b2f728f7092307e6c37 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 11 Jul 2010 20:43:27 +0200 Subject: allow small files to be excluded from deletion Signed-off-by: Florian Pritz --- system/application/config/example/config.php | 4 ++++ system/application/controllers/file.php | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/system/application/config/example/config.php b/system/application/config/example/config.php index b9ce20468..af54fb383 100755 --- a/system/application/config/example/config.php +++ b/system/application/config/example/config.php @@ -341,6 +341,10 @@ $config['upload_path'] = FCPATH.'data/uploads'; $config['upload_max_size'] = 256*1024*1024; $config['upload_max_text_size'] = 2*1024*1024; $config['upload_max_age'] = 60*60*24*5; // 5 days + +// won't be deleted +$config['small_upload_size'] = 1024*10; // 10KB + $config['passwordsalt'] = ''; // just enter any string you want here /* End of file config.php */ diff --git a/system/application/controllers/file.php b/system/application/controllers/file.php index d772a3478..a07debc40 100644 --- a/system/application/controllers/file.php +++ b/system/application/controllers/file.php @@ -131,16 +131,24 @@ class File extends Controller { function cron() { $oldest_time = (time()-$this->config->item('upload_max_age')); + $small_upload_size = $this->config->item('small_upload_size'); $query = $this->db->query('SELECT hash, id FROM files WHERE date < ?', array($oldest_time)); foreach($query->result_array() as $row) { $file = $this->file_mod->file($row['hash']); - if(file_exists($file) && filemtime($file) < $oldest_time) { - unlink($file); - $this->db->query('DELETE FROM files WHERE hash = ?', array($row['hash'])); - } else { + if (!file_exists($file)) { $this->db->query('DELETE FROM files WHERE id = ? LIMIT 1', array($row['id'])); + continue; + } + + if (filesize($file) > $small_upload_size) { + if (filemtime($file) < $oldest_time) { + unlink($file); + $this->db->query('DELETE FROM files WHERE hash = ?', array($row['hash'])); + } else { + $this->db->query('DELETE FROM files WHERE id = ? LIMIT 1', array($row['id'])); + } } } } -- cgit v1.2.3-24-g4f1b