大家好我是一个新的codeigniter。我已经创建了代码更新图像,隐藏了表单,但我从隐藏的不传递值到形成图像用户文件:(我现在非常需要帮助吗?或者任何人都可以提供有关的源代码将图像更新到codigniter上的数据库。
<form action="<?php echo base_url()."./site_admin/update_menu/".$this->uri->segment(3); ?>" method="post" enctype="multipart/form-data">
<?php
$id = $this->uri->segment(3);
$sql = $this->db->get_where('menu',array('id_menu' => $id));
$row = $sql->row(); ?>
<?php $idcat = $row->cate_id ?>
<table class="tab" style="width:100%">
<tr>
<td>Categories Name:</td>
<td>
<select style="padding:6px;background:#C2C2C2;font-weight: bold;" name="cate">
<?php
$query = $this->db->get('categories_menu');
foreach($query->result() as $lazy){
$select = "";
if($lazy->id == $idcat){
$select = "selected";
}
echo "<option $select value='".$lazy->id."'>".$lazy->cate_name_menu."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Upload image:</td>
<td><input type="file" name="userfile" style="width:190px;height:35px;font-weight: bold;background:#C2C2C2;" ></td>
<td><input type="hidden" name="mono" value="<?php echo $row->image; ?>"></td>
</td>
</tr>
<tr>
<td>Title:</td>
<td><textarea class="title" name="title" cols="100" rows="4"><?php echo $row->title; ?></textarea></td>
</tr>
<tr>
<td>Description:</td>
<td><textarea rows="15" name="description" class="dess" ><?php echo $row->description; ?></textarea><td>
</tr>
<tr>
<td>Prices</td>
<td><textarea class="price" name="price" cols="40" rows="4"><?php echo $row->prices; ?></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input style="width:100px; padding:10px;font-weight: bold;background:#1F1F1F;color:white;" type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>
控制器: function update_menu(){
$id = $this->uri->segment(3);
$img1 = $this->input->post('userfile');
$img2 = $this->input->post('mono');
if($img1 == ""){
$img1 = $img2;
$datas = array(
'cate_id' => $this->input->post('cate'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'prices' => $this->input->post('price'),
'image' => $img1
);
$this->db->where('id_menu', $id);
$this->db->update('menu',$datas);
redirect('./site_admin/edit_menu/'.$id);
}else{
$id = $this->uri->segment(3);
$updata = array(
'upload_path' => './images/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '5000',
'max_width' => '4000',
'max_height' => '2800'
);
$this->load->library('upload',$updata);
$this->upload->do_upload('userfile');
$nampic = $this->upload->data();
$data = array(
'cate_id' => $this->input->post('cate'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'prices' => $this->input->post('price'),
'image' => $nampic['file_name']
);
$this->db->where('id_menu', $id);
$this->db->update('menu',$data);
redirect('./site_admin/edit_menu/'.$id);
}
}