I'm working with grocery crud for some operations on the backend, and I need to upload 5 pictures (3 of them with the same width and height and the other 2 with diferents sizes) but, when I try to upload with set_field_upload
, all the files are uploaded with one size. I expected diferents sizes. I tried too working with GD2
( Codeigniter
version) but I don't know if with grocery_crud
I can do that.
public function marcas(){
$this -> load -> view('header');
$this -> load -> view('leftbar');
$this -> grocery_crud -> set_theme('datatables');
$this -> grocery_crud -> set_table('marcas');
$this -> grocery_crud -> set_subject('Marcas');
$this -> grocery_crud -> columns('nombre','descripcion','texto','logo');
$this -> grocery_crud -> set_relation('id_tipo_marca','tipo_marcas','nombre');
$this -> grocery_crud -> display_as('id','ID');
$this -> grocery_crud -> display_as('id_tipo_marca','Tipo Marca');
$this -> grocery_crud -> display_as('nombre','Nombre');
$this -> grocery_crud -> display_as('descripcion','Descripcion');
$this -> grocery_crud -> display_as('texto','Texto');
$this -> grocery_crud -> display_as('link','Link');
$this -> grocery_crud -> display_as('logo','Logo');
$this -> grocery_crud -> set_field_upload('logo','../img');
$this -> grocery_crud -> callback_after_upload(array($this, 'example_callback_after_upload_logo'));
$this -> grocery_crud -> display_as('imagen','Imagen Grande');
$this -> grocery_crud -> display_as('imagen2','Imagen Pequeña 1');
$this -> grocery_crud -> display_as('imagen3','Imagen Pequeña 2');
$this -> grocery_crud -> display_as('imagen4','Imagen Pequeña 3');
$this -> grocery_crud -> set_field_upload('imagen','../img/grande');
$this -> grocery_crud -> callback_after_upload(array($this, 'example_callback_after_upload_grande'));
$this -> grocery_crud -> set_field_upload('imagen2','../img/thumb');
$this -> grocery_crud -> set_field_upload('imagen3','../img/thumb');
$this -> grocery_crud -> set_field_upload('imagen4','../img/thumb');
$this -> grocery_crud -> callback_after_upload(array($this, 'example_callback_after_upload_thumb'));
$output = $this -> grocery_crud -> render();
$this -> _example_output($output);
$this -> load -> view('footer');
}
function example_callback_after_upload_grande($uploader_response,$field_info,$files_to_upload){
$this -> load -> library ('image_moo');
$file_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name;
$this -> image_moo -> load($file_uploaded) ->resize_crop(317,140)->save($file_uploaded, true);
return true;
var_dump($uploader_response);die;
function example_callback_after_upload_logo($uploader_response,$field_info,$files_to_upload){
$this -> load -> library ('image_moo');
$file_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name;
$this -> image_moo -> load($file_uploaded) ->resize(125,83)- >save($file_uploaded, true);
return true;
var_dump($uploader_response);die;
}
function example_callback_after_upload_thumb($uploader_response,$field_info,$files_to_upload){
$this -> load -> library ('image_moo');
$file_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name;
$this -> image_moo -> load($file_uploaded) ->resize_crop(317,140)->save($file_uploaded, true);
return true;
var_dump($uploader_response);die;
}
This is my solution.
public function marcas(){
...
$this->grocery_crud->callback_after_upload(array($this, 'reImage_callback_after_upload'));
...
}
public function reImage_callback_after_upload($uploader_response, $field_info, $files_to_upload) {
$this -> load -> library('image_moo');
switch ($field_info->field_name) {
case 'logo':
$file_uploaded = $field_info -> upload_path . '/' . $uploader_response[0] -> name;
$this -> image_moo -> load($file_uploaded) -> resize_crop(20, 20) -> save($file_uploaded, true);
return true;
break;
case 'imagen':
$file_uploaded = $field_info -> upload_path . '/' . $uploader_response[0] -> name;
$this -> image_moo -> load($file_uploaded) -> resize_crop(30, 30) -> save($file_uploaded, true);
return true;
break;
case 'imagen2':
$file_uploaded = $field_info -> upload_path . '/' . $uploader_response[0] -> name;
$this -> image_moo -> load($file_uploaded) -> resize_crop(40, 40) -> save($file_uploaded, true);
return true;
break;
case 'imagen3':
$file_uploaded = $field_info -> upload_path . '/' . $uploader_response[0] -> name;
$this -> image_moo -> load($file_uploaded) -> resize_crop(50, 50) -> save($file_uploaded, true);
return true;
break;
case 'imagen4':
$file_uploaded = $field_info -> upload_path . '/' . $uploader_response[0] -> name;
$this -> image_moo -> load($file_uploaded) -> resize_crop(60, 60) -> save($file_uploaded, true);
return true;
break;
default:
return false;
break;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.