0

我有一个用于将公司添加到我的数据库的表格。我添加了一个名为 Logo 的字段。我想使用此字段,以便用户可以为他们的公司上传徽标。我在表单中使用 Codeigniter 上传类。

我的公司表如下所示:

Companies
---------
id
companyname
address
postalcode
country
email
website
logo

我的表格看起来像这样:

<tr>
<td><?= form_label('Bedrijfsnaam:');?></td>
<td><?= form_input('Bedrijfsnaam');?><small> (Spaties niet toegestaan)</small></td>
</tr>

<tr>
<td><?= form_label('Adres:');?></td>
<td><?= form_input('Adres');?></td>
</tr>

<tr>
<td><?= form_label('Postcode:');?></td>
<td><?= form_input('Postcode');?></td>
</tr>

<tr>
<td><?= form_label('Plaats:');?></td>
<td><?= form_input('Plaats');?></td>
</tr>

<tr>
<td><?= form_label('Telefoonnummer:');?></td>
<td><?= form_input('Telefoonnummer');?></td>
</tr>

<tr>
<td><?= form_label('Website:');?></td>
<td><?= form_input('Website');?></td>
</tr>

<tr>
<td><?= form_label('Email:');?></td>
<td><?= form_input('Email');?></td>
</tr>

<tr>
<td><?= form_label('Profiel:');?></td>
<td><?= form_textarea('Profiel');?></td>
</tr>

<tr>
<td><?= form_label('Categorieen:'); ?></td>
<td><?= form_dropdown('categorieen', $opties); ?></td>
</tr>

<tr>
<td><?= form_label('Logo:'); ?></td>
<td><input type="file" name="logo" size="20" /></td>
</tr>

<tr>
<td><?= form_submit('submit', 'Opslaan');?> <?= form_reset('reset', 'Reset');?></td>
</tr>

我的模型如下所示:

    $data1 = array( 
        'Bedrijfsnaam' => $this->input->post('Bedrijfsnaam'), 
        'Postcode' => $this->input->post('Postcode'), 
        'Plaats' => $this->input->post('Plaats'), 
        'Telefoonnummer' => $this->input->post('Telefoonnummer'), 
        'Email' => $this->input->post('Email'), 
        'Website' => $this->input->post('Website'), 
        'Profiel' => $this->input->post('Profiel'), 
        'Adres' => $this->input->post('Adres'), 
        'logo' => $this->input->post('logo') 
    ); 
    $this->db->insert('bedrijven',$data1); 

我知道这行不通,但我不知道该怎么做。

我有另一个上传表单,但这仅用于上传图片,不适用于徽标。

使用上传类执行此操作的最佳方法是什么?


编辑:

添加新公司时,我得到一个空白字段。

我的控制器:

    function addbedrijven()
    {
        $config['upload_path'] = './assets/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '1000';
        $config['max_width']  = '';
        $config['max_height']  = '';
        $config['overwrite'] = TRUE;
        $config['remove_spaces'] = TRUE;

        $this->load->library('upload', $config);

        if($this->upload->do_upload('logo')){

        $logo_image_data = $this->upload->data();

        }
        $this->members_model->addbedrijf();
        redirect('members/index');
    }

我的模型:

    function addbedrijf() 
    { 
        $logo_image_data = $this->upload->data();

        $data1 = array( 
            'Bedrijfsnaam' => $this->input->post('Bedrijfsnaam'), 
            'Postcode' => $this->input->post('Postcode'), 
            'Plaats' => $this->input->post('Plaats'), 
            'Telefoonnummer' => $this->input->post('Telefoonnummer'), 
            'Email' => $this->input->post('Email'), 
            'Website' => $this->input->post('Website'), 
            'Profiel' => $this->input->post('Profiel'), 
            'Adres' => $this->input->post('Adres'), 
            'logo' => $logo_image_data['full_path'] 
        ); 
        $this->db->insert('bedrijven',$data1); 
    }
4

1 回答 1

0

您可以codeigniter upload在同一个表单中使用该类

      $config_logo_image = array(
        'allowed_types' => 'jpg|jpeg|gif|png',
        'upload_path' => UPLOAD_PATH,
        'max_size' => 2000,
        );
    $this->load->library('upload', $config_logo_image );                    
    if($this->upload->do_upload('logo_image')){

    $logo_image_data = $this->upload->data();

    }

并通过$data数组中的这些数据

    $data1 = array( 
    'Bedrijfsnaam' => $this->input->post('Bedrijfsnaam'), 
    'Postcode' => $this->input->post('Postcode'), 
    'Plaats' => $this->input->post('Plaats'), 
    'Telefoonnummer' => $this->input->post('Telefoonnummer'), 
    'Email' => $this->input->post('Email'), 
    'Website' => $this->input->post('Website'), 
    'Profiel' => $this->input->post('Profiel'), 
    'Adres' => $this->input->post('Adres'), 
    'logo' => $logo_image_data ['full_path']  // it is full path of image 
); 
$this->db->insert('bedrijven',$data1); 

'logo' =>$logo_image_data ['file_name'] //only file name

希望有意义

于 2013-05-21T10:15:26.150 回答