From 70c40f4e7297e223636514adeb71ed6fe609ade5 Mon Sep 17 00:00:00 2001 From: atomaka Date: Sat, 5 Nov 2011 12:35:17 -0400 Subject: [PATCH] Setup so controller takes uploads. Currently an issue with the mimetype coming from the jquery upload plugin. --- application/controllers/upload.php | 21 +++++++++++++++++++++ js/upload.js | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/application/controllers/upload.php b/application/controllers/upload.php index 071bc59..0196f2a 100644 --- a/application/controllers/upload.php +++ b/application/controllers/upload.php @@ -4,4 +4,25 @@ class Upload extends CI_Controller { public function index() { $this->template->load('template','upload'); } + + public function process() { + header('Content-Type: application/json',true); + + $config['file_name'] = 135; + $config['max_size'] = 2048; + $config['upload_path'] = './uploads/'; + // $config['allowed_types'] = 'gif|jpg|jpeg|png|bmp'; + $config['allowed_types'] = 'jpg'; + $this->load->library('upload', $config); + + if (!$this->upload->do_upload('image')) { + print_r($this->upload->data()); + $message = array('type' => 'error', 'status' => $this->upload->display_errors()); + } else { + $data = array('upload_data' => $this->upload->data()); + $message = array('type'=>'success','status'=>'Uploaded successfully','file'=>'http://screens.p5dev.com/' . $data['file_name']); + } + + echo json_encode($message); + } } \ No newline at end of file diff --git a/js/upload.js b/js/upload.js index 1e50181..728762c 100644 --- a/js/upload.js +++ b/js/upload.js @@ -8,7 +8,7 @@ $(function(){ maxfiles: 5, maxfilesize: 2, - url: 'upload.php', + url: '/upload/process/', uploadFinished:function(i,file,response){ if(response.type == 'error') {