我有一个编辑我的公司信息的编辑表。我还有一个用于上传徽标的字段。当我单击选择文件并单击提交(表单)时,它将文件名存储在我的数据库中,例如 imagename.jpg。
我还想将图像添加到文件夹 assets/uploads/。我尝试使用 codeigniter 上传类,就像我在其他上传表单上所做的一样,但是这个不起作用。我只是不知道为什么。
这是我的编辑表格:
<?= form_open_multipart('members/update/'.$id);?>
//other fields for editing company
<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>
</table>
<?= form_close()?>
我的控制器:
function update() //de update functie voor bovenstaande functie.
{
$id = $this->uri->segment(3);
$data = 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'),
);
if($this->input->post('logo')) { $data['logo'] = $this->input->post('logo'); }
$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())
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
}
$this->members_model->updatebedrijf($id, $data);
$b = $this->session->userdata('idbedrijven');
redirect("members/$b");
}
function updatebedrijf($id, $data)
{
foreach($this->input->post('categorieen') as $cat){
$this->db->where('idbedrijven', $id);
$this->db->update('bedrijven', $data);
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
};
}
我的模型:
function updatebedrijf($id, $data)
{
foreach($this->input->post('categorieen') as $cat){
$this->db->where('idbedrijven', $id);
$this->db->update('bedrijven', $data);
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
};
}
它只是不上传。该路径与我的其他上传功能相同。那个工作正常。