1

バックエンドでのいくつかの操作で食料品のクラッドを使用しています。5枚の写真をアップロードする必要があります(3枚は同じ幅と高さで、残りの2枚はサイズが異なります)が、でアップロードしようとするとset_field_upload、すべてファイルは1つのサイズでアップロードされます。私は異なるサイズを期待していました。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;

}
4

1 に答える 1

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;
    }
}
于 2013-03-12T03:39:12.403 に答える