enter image description here我想将我的图片上传到上载目录,但是当我单击“提交”按钮发送发帖请求时,我的代码运行了,但并没有将已提交的图像插入到上载目录中它运行下面的代码
if (!$this->upload->do_upload()) {
$errors = array('error' => $this->upload->display_errors());
$post_image = 'no_image.jpg';
}
因此导致它在我的数据库中显示no_image.jpg。因此,我尝试对其进行编辑,但是似乎无法上传代码,所以我想知道我的代码可能有什么问题。
那是我的控制器文件的一部分。
public function Edit_RoomType()
{
$data['title'] = 'Rooms_model';
$this->form_validation->set_rules('room','RoomType','required');
$this->form_validation->set_rules('Amount','Price Tag','required');
if ($this->form_validation->run() === FALSE) {
$this->load->view('templates/header_Admin');
$this->load->view('Admin/Edit_RoomType', $data);
$this->load->view('templates/footer_Admin');
} else {
//image upload
$config['upload_path'] ='./assets/uploads';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] ='2048';
$config['max_width'] ='500';
$config['max_height'] ='500';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$errors = array('error' => $this->upload->display_errors());
$post_image = 'no_image.jpg';
} else {
$data = array('upload_data' => $this->upload->data());
//setting table field
$post_image = $_FILES['userfile']['name'];
}
$this->Rooms_model->create_room($post_image);
redirect('Admin');
}
}
下面是我的模型文件的一部分
public function create_room($post_image)
{
$Room_type = url_title($this->input->post('room'));
$data = array(
'Room_type' => $Room_type,
'Amount' => $this->input->post('Amount'),
'description' => $this->input->post('description'),
'post_image' => $post_image
);
return $this->db->insert('RoomType',$data);
}