2011-11-05 02:25:17 -04:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Upload extends CI_Controller {
|
|
|
|
public function index() {
|
|
|
|
$this->template->load('template','upload');
|
|
|
|
}
|
2011-11-05 12:35:17 -04:00
|
|
|
|
|
|
|
public function process() {
|
|
|
|
header('Content-Type: application/json',true);
|
|
|
|
|
2011-11-05 13:55:44 -04:00
|
|
|
$temp_name = md5(rand());
|
|
|
|
|
|
|
|
$config['file_name'] = $temp_name;
|
2011-11-05 12:35:17 -04:00
|
|
|
$config['max_size'] = 2048;
|
|
|
|
$config['upload_path'] = './uploads/';
|
2011-11-05 12:59:14 -04:00
|
|
|
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
|
2011-11-05 12:35:17 -04:00
|
|
|
$this->load->library('upload', $config);
|
|
|
|
|
|
|
|
if (!$this->upload->do_upload('image')) {
|
|
|
|
$message = array('type' => 'error', 'status' => $this->upload->display_errors());
|
|
|
|
} else {
|
2011-11-05 13:55:44 -04:00
|
|
|
$upload = $this->upload->data();
|
|
|
|
|
|
|
|
$this->load->model('fileupload');
|
|
|
|
$file_name = $this->fileupload->add_upload($upload['file_ext'], $upload['orig_name']);
|
|
|
|
|
|
|
|
rename($upload['full_path'], $upload['file_path'] . $file_name . $upload['file_ext']);
|
|
|
|
|
|
|
|
$message = array('type'=>'success','status'=>'Uploaded successfully', 'file'=>'http://screens.p5dev.com/' . $file_name);
|
2011-11-05 12:35:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($message);
|
|
|
|
}
|
2011-11-05 02:25:17 -04:00
|
|
|
}
|