penyimpanan file di buat write accessible. Ukuran max di php.ini juga di atur agar sesuai
dengan yang kita inginkan. Perhatikan baris berikut pada php.
file_uploads=on // Buat menjadi on
post_max_size = 2M // Edit ukuran file nya sesuai dengan yang anda inginkan.
upload_tmp_dir=”/opt/lampp/htdocs” // Folder ini harus write accssible
Setting upload nya adalah sbb :
$config['upload_path']='./uploads/'; // Folder penyimpanan file. Musti Write accessible
$config['allowed_types']='gif|jpg|png';
$config['max_size']='100';
$config['max_width']='1024';
$config['max_height']='768';
$this->load->library('upload',$config);
// Jika kita meletakkan library uploading file di dalam file autoload.php, maka syntax di bawah
ini yang perlu kita taruh :
$this->upload->initialize($config);
$this->upload->do_upload()
Fungsi : Untuk melakukan eksekusi uploading file
Contoh :
<?php
class Upload extends Controller {
function Upload()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>
Agar form dapat melakukan uploading file, maka tipe enctype suatu form haruslah berbentuk
multipart/form-data.
<form method=”post” enctype=”multipart/form-data”>
Posting Komentar