From 4397fbcba26037acc2c1323e73e5a54200da7c17 Mon Sep 17 00:00:00 2001
From: Florian Pritz
Date: Fri, 13 Apr 2012 19:25:45 +0200
Subject: Add do_paste() and remove ajax from upload_form
If the session has timed out, javascript will get the login page and try
to redirect to "base_url/$htmlcode" which will obviously fail. Instead
of fixing the js code, reintroduce do_paste and use it.
Signed-off-by: Florian Pritz
---
application/controllers/file.php | 44 ++++++++++++++++++++++++++++++----
application/views/file/upload_form.php | 17 ++++++-------
2 files changed, 46 insertions(+), 15 deletions(-)
(limited to 'application')
diff --git a/application/controllers/file.php b/application/controllers/file.php
index b8b22f12b..49434699c 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -205,16 +205,50 @@ class File extends CI_Controller {
$this->load->view($this->var->view_dir.'/footer', $this->data);
}
- // Handles uploaded files
- function do_upload()
+ // Handle pastes
+ function do_paste()
{
$this->muser->require_access();
- if ($this->uri->segment(3)) {
- $this->var->cli_client = true;
- $this->var->view_dir = "file_plaintext";
+ $content = $this->input->post("content");
+ $filesize = strlen($content);
+ $filename = "stdin";
+
+ if(!$content) {
+ $this->output->set_status_header(400);
+ $this->data["msg"] = "Nothing was pasted, content is empty.";
+ $this->load->view($this->var->view_dir.'/header', $this->data);
+ $this->load->view($this->var->view_dir.'/upload_error', $this->data);
+ $this->load->view($this->var->view_dir.'/footer');
+ return;
+ }
+
+ if ($filesize > $this->config->item('upload_max_size')) {
+ $this->output->set_status_header(413);
+ $this->load->view($this->var->view_dir.'/header', $this->data);
+ $this->load->view($this->var->view_dir.'/too_big');
+ $this->load->view($this->var->view_dir.'/footer');
+ return;
}
+ $id = $this->file_mod->new_id();
+ $hash = md5($content);
+
+ $folder = $this->file_mod->folder($hash);
+ file_exists($folder) || mkdir ($folder);
+ $file = $this->file_mod->file($hash);
+
+ file_put_contents($file, $content);
+ chmod($file, 0600);
+ $this->file_mod->add_file($hash, $id, $filename);
+ $this->file_mod->show_url($id, $extension);
+ }
+
+ // Handles uploaded files
+ function do_upload()
+ {
+ $this->muser->require_access();
+
$extension = $this->input->post('extension');
if(!isset($_FILES['file']) || $_FILES['file']['error'] !== 0) {
$this->output->set_status_header(400);
diff --git a/application/views/file/upload_form.php b/application/views/file/upload_form.php
index ce1d00498..3ab70eb62 100644
--- a/application/views/file/upload_form.php
+++ b/application/views/file/upload_form.php
@@ -6,18 +6,15 @@
+ OR
+
+
+
+
+
+
--
cgit v1.2.3-24-g4f1b