Upload File pada Codeigniter 3

Buat controller dengan nama upload. Untuk melakukan proses upload pada codeigniter dibutuhkan library upload.
public function upload()
{
        $this->load->library('upload', $config);
        $config['upload_path']          = FCPATH.'public\files\upload';
        $config['max_size']             = 0;
        $config['allowed_types']        = "jpg|png";
	$config['overwrite']            = true;
		
        
      if ( ! $this->upload->do_upload('upload'))
      {
          $error = array('error' => $this->upload->display_errors());
          //print_r($error );
          $response["status"] = false;
          $response["message"] = $error;
      }
      else
      {   
        $data = array('upload_data' => $this->upload->data());
        $response["status"] = true;
        $response["message"] = "Data berhasil ditambahkan";        
        
      }

    echo json_encode($response);
}


Posting Komentar

Lebih baru Lebih lama