jyr (owner)

Revisions

gist: 219080 Download_button fork
public
Public Clone URL: git://gist.github.com/219080.git
Embed All Files: show embed
uploader.php #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Carga de una imagen y generacion de thumbnail
*/
function post_agregar_foto()
{
$config['upload_path'] = './application/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$json = "{'errorMsg':".$error['error']."}";
}
else
{
$this->load->library('form_validation');
 
$this->form_validation->set_rules('descripcion', 'Descripcion', 'trim|required|xss_clean');
 
if ($this->form_validation->run() == FALSE)
{
$json = "{'errorMsg':'Los datos no son correctos.'}";
}
else
{
$imagen = $_FILES['userfile']['name'];
$thumb = $this->galeria_model->agregar_foto($imagen);
rename($config['upload_path'].$_FILES['userfile']['name'],$config['upload_path'].$thumb);
$data = array('upload_data' => $this->upload->data());
$this->__thumbnail($imagen,$thumb);
$json = "{'successMsg':' Imagen agregada'}";
}
}
$data['ajax'] = $json;
return $this->load->view('ajax', $data);
}
function __thumbnail($image, $thumb)
{
//$config['image_library'] = 'gd2';
$config['source_image'] = './application/uploads/'.$thumb;
$config['new_image'] = './application/uploads/'.$thumb;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}