summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-12-07 16:50:15 +0100
committerFlorian Pritz <bluewind@xssn.at>2010-12-07 16:50:15 +0100
commitdf391ca93099e17f15875366dce37cacc9079f42 (patch)
treef1984b3d3f9f0c359ac288e3aaa80fe7c4b2cdcb /system
parenta79798223a71874a70981c07e0bcc79b4dcabc28 (diff)
remove old files when viewing; catch non existent files
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to 'system')
-rw-r--r--system/application/controllers/file.php5
-rw-r--r--system/application/models/file_mod.php20
2 files changed, 24 insertions, 1 deletions
diff --git a/system/application/controllers/file.php b/system/application/controllers/file.php
index 0ed66b511..a8ab406f7 100644
--- a/system/application/controllers/file.php
+++ b/system/application/controllers/file.php
@@ -35,14 +35,17 @@ class File extends Controller {
// Try to guess what the user would like to do.
// File uploads should be checked first because they are usually big and
// take quite some time to upload.
+ $id = $this->uri->segment(1);
if(isset($_FILES['file'])) {
$this->do_upload();
} elseif ($this->input->post('content')) {
$this->do_paste();
- } elseif ($this->file_mod->id_exists($this->uri->segment(1))) {
+ } elseif ($this->file_mod->id_exists($id)) {
$this->file_mod->download();
} elseif ($this->var->cli_client) {
die("No upload or unknown ID requested.\n");
+ } elseif ($id != "file") {
+ $this->file_mod->non_existant();
} else {
$this->upload_form();
}
diff --git a/system/application/models/file_mod.php b/system/application/models/file_mod.php
index 2d3fc8ccf..0c52bb012 100644
--- a/system/application/models/file_mod.php
+++ b/system/application/models/file_mod.php
@@ -138,6 +138,15 @@ class File_mod extends Model {
}
}
+ function non_existant()
+ {
+ $data["title"] = "Not Found";
+ $this->output->set_status_header(404);
+ $this->load->view('file/header', $data);
+ $this->load->view('file/non_existant', $data);
+ $this->load->view('file/footer', $data);
+ }
+
// download a given ID
// TODO: make smaller
function download()
@@ -150,6 +159,17 @@ class File_mod extends Model {
$file = $this->file($filedata['hash']);
if ($this->id_exists($id) && file_exists($file)) {
+ $oldest_time = (time()-$this->config->item('upload_max_age'));
+ if (filesize($file) > $this->config->item("small_upload_size") && $filedata["date"] < $oldest_time) {
+ if (filemtime($file) < $oldest_time) {
+ unlink($file);
+ $this->db->query('DELETE FROM files WHERE hash = ?', array($filedata['hash']));
+ } else {
+ $this->db->query('DELETE FROM files WHERE id = ? LIMIT 1', array($id));
+ }
+ $this->non_existant();
+ return;
+ }
// MODIFIED SINCE SUPPORT -- START
// helps to keep traffic low when reloading an image
$filedate = filectime($file);