in View :
<?= form_open_multipart(base_url('upload/do_upload'));?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
---------------------------------------------------------------------------------------
in controller :
<?php
class Upload extends CI_Controller {
function index() {
$this->load->view('upload/form_upload');
}
function do_upload() {
// ------------------------------------
// configurasi dulu kemudian di load
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
// $config['max_size'] = '100';
// $config['max_width'] = '1024';
// $config['max_height'] = '768';
// ------------------------------------
// load library upload
$this->load->library('upload', $config);
// ------------------------------------
// script di bawah ini memanggil function di library
$this->upload->do_upload();
$data = $this->upload->data();
$dtUpload = [
'nm_file' => $data['file_name'],
'size' => $data['file_size'],
];
// ------------------------------------
// kemudian simpan (insert)
$this->db->insert('download', $dtUpload);
}
}