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());
|
|
|
|
|
2011-11-11 16:13:12 -05:00
|
|
|
// cannot move partial config to config directory with this class?
|
2011-11-06 00:57:35 -04:00
|
|
|
$config = array(
|
|
|
|
'max_size' => 2048,
|
|
|
|
'upload_path' => './uploads/',
|
|
|
|
'allowed_types' => 'gif|jpg|jpeg|png|bmp'
|
|
|
|
);
|
2011-11-11 16:13:12 -05:00
|
|
|
// end stuff that should be removed.
|
|
|
|
$config['file_name'] = $temp_name;
|
2011-11-06 00:57:35 -04:00
|
|
|
|
2011-11-11 16:13:12 -05:00
|
|
|
$this->load->library('upload');
|
|
|
|
$this->upload->initialize($config);
|
2011-11-05 12:35:17 -04:00
|
|
|
|
|
|
|
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();
|
2011-11-08 18:20:43 -05:00
|
|
|
|
2011-11-11 16:13:12 -05:00
|
|
|
$hash = md5_file($upload['full_path']);
|
|
|
|
$width = $upload['image_width'];
|
|
|
|
$height = $upload['image_height'];
|
|
|
|
$size = $upload['file_size'];
|
2011-11-05 13:55:44 -04:00
|
|
|
|
|
|
|
$this->load->model('fileupload');
|
2011-11-08 15:40:41 -05:00
|
|
|
$duplicate = $this->fileupload->check_duplicate($hash);
|
|
|
|
|
|
|
|
if($duplicate) {
|
2011-11-08 15:45:27 -05:00
|
|
|
unlink($upload['full_path']);
|
|
|
|
|
2011-11-11 16:13:12 -05:00
|
|
|
$message = array(
|
|
|
|
'type' => 'error',
|
|
|
|
'status' =>'You are attempting to upload a duplicate of <a href="' . base_url($duplicate) . '" style="text-decoration:underline">image ' . $duplicate . '</a>.'
|
|
|
|
);
|
2011-11-08 15:40:41 -05:00
|
|
|
} else {
|
2011-11-08 18:20:43 -05:00
|
|
|
$file_name = $this->fileupload->add_upload($upload['file_ext'], $upload['client_name'],$width,$height,$size,$hash);
|
2011-11-08 15:45:27 -05:00
|
|
|
|
2011-11-08 15:40:41 -05:00
|
|
|
rename($upload['full_path'], $upload['file_path'] . $file_name . $upload['file_ext']);
|
|
|
|
|
|
|
|
$config = array(
|
2011-11-11 16:13:12 -05:00
|
|
|
'source_image' => $upload['file_path'] . $file_name . $upload['file_ext'],
|
|
|
|
'new_image' => './thumbs/' . $file_name . $upload['file_ext'],
|
2011-11-08 15:40:41 -05:00
|
|
|
);
|
|
|
|
|
2011-11-11 16:13:12 -05:00
|
|
|
$this->load->library('image_lib');
|
|
|
|
$this->image_lib->initialize($config);
|
2011-11-08 15:40:41 -05:00
|
|
|
$this->image_lib->resize();
|
|
|
|
|
|
|
|
$message = array('type'=>'success','status'=>'Uploaded successfully', 'file'=>base_url($file_name));
|
|
|
|
}
|
2011-11-05 12:35:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($message);
|
|
|
|
}
|
2011-11-05 02:25:17 -04:00
|
|
|
}
|