Codeigniter上传错误

Áko*_*rős 3 codeigniter

请帮我!我想用 codeigniter 上传文件,但这返回错误。这是上传者:

class Uploader extends CI_Model
 {
    function __construct()
    {
        parent::__construct();

        $config['upload_path']   = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png|exe|xls|doc|docx|xlsx|rar|zip';
        $config['max_size']      = '8192'; // kbytes
        $config['encrypt_name']  = TRUE;

        $this->load->library( 'upload', $config );
        $this->response = '';
        $this->success  = TRUE;
    }

    /**
     *  Triggers upload
     *  returns the file's details on success or false
     */
    function upload( $field_name )
    {
        if ( !$this->upload->do_upload( $field_name ) )
        {
            $this->success  = FALSE;
            $this->response = $this->upload->display_errors();
            return false;
        }
        else
        {
            $this->success  = TRUE;
            $this->response = $this->upload->data();
            return $this->response['file_name']; 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Downloads::$required_empty

Filename: core/Model.php

Line Number: 51
Run Code Online (Sandbox Code Playgroud)

自动加载数据库配置已打开。请帮我。

ABo*_*rty 5

尝试这个

if($this->input->post())
{
   $file_element_name = 'image';  //this is the name of your input file. for example "image"
   if ($_FILES['image']['name']!= "")
   {
      $config['upload_path'] = './uploads/';
      $config['allowed_types'] = 'gif|jpg|png|exe|xls|doc|docx|xlsx|rar|zip';
      $config['max_size']      = '8192'; 
      $config['remove_spaces']=TRUE;  //it will remove all spaces
      $config['encrypt_name']=TRUE;   //it wil encrypte the original file name
      $this->load->library('upload', $config);

      if (!$this->upload->do_upload($file_element_name))
      {
         $error = array('error' => $this->upload->display_errors());
         $this->session->set_flashdata('error',$error['error']);
         redirect('controller_name/function_name','refresh');
      }
      else
      {
         $data = $this->upload->data();
         return $data['file_name'];          
      }
      $this->session->set_flashdata('msg','success message');
      redirect('controller_name/function_name','refresh');
   }
   else
   {
        //if no file uploaded the do stuff here
   } 
}
Run Code Online (Sandbox Code Playgroud)

如果您遇到任何问题,请告诉我。