0

これはフォームアクションまたはその他のものです

<?php
echo form_open_multipart("/Register/registerformModel",
                         array("name"=>"subform2","id"=>"subform2"));
?>

これはHTMLファイルです

<input name="userfile" id="userfile" type="file" class="input"/>

これは、画像ファイルをデータベースに挿入するために使用される機能です

public function registerformModel()
{
    $this->load->model("common_model");
    $config['upload_path'] = $this->config->item('upload_url_path').'images/member/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['file_name'] = date('Ymd_his_').rand(10,99).rand(10,99).rand(10,99);
    $config['overwrite'] = FALSE;
    $config['max_size'] = '0';
    $config['max_width'] = '0';
    $config['max_height'] = '0';
    $config['max_filename'] = '0';
    $config['remove_spaces'] = FALSE;
    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {
        $data['upload_data']['file_name'] = '';
        echo $this->upload->display_errors('<p style="color:#FF0000;">','</p>');                    
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
        $config['image_library'] = 'gd2';
        $config['source_image'] = $config['upload_path'].$data['upload_data']['file_name'];
        $config['quality'] = '100%';
        $config['width'] = 50;
        $config['height'] = 50;
        $config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        $this->load->library('image_library', $config);
        $this->image_lib->resize();
    }

    $data['query'] = array(
            'image' => $data['upload_data']['file_name']
            );  

    $num = $this->common_model->insert('member',$data['query']);
    $msg = ($num > 0) ? $this->lang->line('added') : $this->lang->line('not_added');
    $this->session->set_flashdata('msg', $msg);         
}

クエリは正常に実行されていますが、画像が挿入されていません。

4

1 に答える 1

1

この行 $this->upload->do_upload() を $this->upload->do_upload( 'userfile' )に置き換えてもらえますか

サイズ変更した画像を任意のフォルダに保存する場合は、 $config['new_image'] = "サイズ変更した画像を保存するパス"; と記述してください。

私はこのコードを試してみましたが、うまく機能しています。

      public function registerformModel(){
        $this->load->model("common_model");
        $config['upload_path'] = 'uploads/test';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['file_name'] = date('Ymd_his_').rand(10,99).rand(10,99).rand(10,99);
        $config['overwrite'] = FALSE;
        $config['max_size'] = '0';
        $config['max_width']  = '0';
        $config['max_height']  = '0';
        $config['max_filename']  = '0';
        $config['remove_spaces']  = FALSE;
        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload())
        {
            $data['upload_data']['file_name'] = '';
            echo $this->upload->display_errors('<p style="color:#FF0000;">','</p>');                    
        }
        else
        { 
        $data = array('upload_data' => $this->upload->data());
        $config['image_library'] = 'gd2';
        $config['source_image'] = $config['upload_path'].$data['upload_data']['file_name'];
        $config['quality'] = '100%';
        $config['width'] = 50;
        $config['height'] = 50;
        $config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        $this->load->library(**'image_lib'**, $config);
        $this->image_lib->resize();
        }

        $data['query'] = array(
                'image' => $data['upload_data']['file_name']
                );  

        $num = $this->common_model->insert('member',$data['query']);
        $msg = ($num > 0) ? $this->lang->line('added') : $this->lang->line('not_added');
        $this->session->set_flashdata('msg', $msg);         
        }

ではごきげんよう

于 2013-10-30T07:04:55.127 に答える