注册新用户时,用户可以上传照片或将其保留为默认值,但在 CI 中如果没有选择文件则$this->upload->do_upload()
返回 false。我怎样才能绕过这个错误。下面是我的方式:
if($this->form_validation->run()==FALSE)
{
$this->load->view('add_item_form', array('error' =>''));
}
else
{
$config['upload_path'] = 'images/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$no_photo_error = "<p>You did not select a file to upload.</p>";
if(!$this->upload->do_upload() AND $this->upload->display_errors() != $no_photo_error)
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('add_item_form', $error);
}
else
{
$data['title'] = 'Add Item';
$this->load->view('success', $data);
}
}
}