вот фрагменты кода, за которыми вы можете следовать:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class UploadFileController extends CI_Controller {
public function __construct() {
parent::__construct();
// add these lines
$this->load->library('upload');
$this->load->helper(array('form', 'url'));
}
public function index(){
$this->load->view('home', array('error' => ' ' ));
}
public function do_upload(){
$config = array(
'upload_path' => "./uploads/", // here add directory path where you want to upload and do not forget to give permission
'allowed_types' => "gif|jpg|png|jpeg|pdf", // you can add many more types
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success',$data);
}
else
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('home', $error);
}
}
}
?>