我正在使用杂货crud在后端进行一些操作,我需要上传5张图片(其中3张图片的宽度和高度相同,另外2张图片尺寸相同)但是,当我尝试上传时set_field_upload
,所有文件都以一种尺寸上传。我期待不同的尺寸。我尝试使用GD2
(Codeigniter
版本),但我不知道是否可以使用grocery_crud
。
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;
}
答案 0 :(得分:2)
这是我的解决方案。
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;
}
}