我是一名新手程序员,而且我的英语不太好。我会问一个关于我的代码的问题。输入图像并将其保存到phpmyadmin
中的数据库时,我感到很困惑。即使输入另一个文件,也会显示noimage.jpg。请帮我解决问题。谢谢
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('posts/create', $data);
$this->load->view('templates/footer');
}
else {
$config['upload_path'] = './assets/images/posts';
$config['allowed_types'] ='gif|jpg|png';
$config['max_size'] ='2048';
$config['max_width'] ='500';
$config['max_height'] ='500';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('userfile')) {
$error = array(
'error' => $this->upload->display_errors()
);
$post_image ='noimage.jpg';
}
else {
//if uploaded
$data = array('upload_data' => $this->upload->data());
$post_image= $_FILES['userfile']['name'];
}
$this->post_model->create_post($post_image);
redirect('posts');
}