如何忽略CodeIgniter';s do_upload()
注册新用户时,用户可以上载照片或将其保留为默认值,但在CI中,如果未选择任何文件如何忽略CodeIgniter';s do_upload(),codeigniter,Codeigniter,注册新用户时,用户可以上载照片或将其保留为默认值,但在CI中,如果未选择任何文件$this->upload->do_upload()将返回false。我怎样才能绕过这个错误呢。以下是我的方式: if($this->form_validation->run()==FALSE) { $this->load->view('add_item_form', array('error' =>''));
$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);
}
}
}
if($this->form\u validation->run()==FALSE)
{
$this->load->view('add_item_form',array('error'=>'');
}
其他的
{
$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=“您没有选择要上载的文件。”;
如果(!$this->upload->do_upload()和$this->upload->display_errors()!=$no_photo_error)
{
$error=array('error'=>$this->upload->display_errors());
$this->load->view('add\u item\u form',$error);
}
其他的
{
$data['title']=“添加项目”;
$this->load->view('success',$data);
}
}
}
试试这个
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);
}elseif(empty($this->upload->data())){
//Check if the file is uploaded .
$data['title'] = 'Add Item';
$this->load->view('success', $data);
}
else
{
$data['title'] = 'Add Item';
$this->load->view('success', $data);
}
}
}
if($this->form\u validation->run()==FALSE){
$this->load->view('add_item_form',array('error'=>'');
}
其他的
{
$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=“您没有选择要上载的文件。”;
如果(!$this->upload->do_upload()和$this->upload->display_errors()!=$no_photo_error)
{
$error=array('error'=>$this->upload->display_errors());
$this->load->view('add\u item\u form',$error);
}elseif(空($this->upload->data()){
//检查文件是否已上载。
$data['title']=“添加项目”;
$this->load->view('success',$data);
}
其他的
{
$data['title']=“添加项目”;
$this->load->view('success',$data);
}
}
}
试试这个
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);
}elseif(empty($this->upload->data())){
//Check if the file is uploaded .
$data['title'] = 'Add Item';
$this->load->view('success', $data);
}
else
{
$data['title'] = 'Add Item';
$this->load->view('success', $data);
}
}
}
if($this->form\u validation->run()==FALSE){
$this->load->view('add_item_form',array('error'=>'');
}
其他的
{
$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=“您没有选择要上载的文件。”;
如果(!$this->upload->do_upload()和$this->upload->display_errors()!=$no_photo_error)
{
$error=array('error'=>$this->upload->display_errors());
$this->load->view('add\u item\u form',$error);
}elseif(空($this->upload->data()){
//检查文件是否已上载。
$data['title']=“添加项目”;
$this->load->view('success',$data);
}
其他的
{
$data['title']=“添加项目”;
$this->load->view('success',$data);
}
}
}