I found some problem regarding saved file upload in codeigniter, i already got some advice from internet, but after i implemented it doesn't worked, let's check this out :
Controller :
function save_data()
{
$in['jenis'] = $this->input->post("jenis");
$in['judul'] = $this->input->post("judul");
$in['nomor'] = $this->input->post("nomor");
$in['tanggal'] = $this->input->post("tanggal");
$in['nilai'] = $this->input->post("nilai");
$in['deskripsi'] = $this->input->post("deskripsi");
$in['penerbit'] = $this->input->post("penerbit");
$acak=rand(00000000000,99999999999);
$bersih=$_FILES['userfile']['name'];
$nm=str_replace(" ","_","$bersih");
$pisah=explode(".",$nm);
$nama_murni=$pisah[0];
$ubah=$acak.$nama_murni; //tanpa ekstensi
$config["file_name"]=$ubah; //dengan eekstensi
$in["lampiran"]=$acak.$nm;
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'exe|sql|psd|pdf|xls|ppt|php|php4|php3|js|swf|Xhtml|zip|wav|bmp|gif|jpg|jpeg|png|html|htm|txt|rtf|mpeg|mpg|avi|doc|docx|xlsx';
$config['max_size'] = '50000';
$config['max_width'] = '1200';
$config['max_height'] = '1200';
$this->load->library('upload', $config);
if(!$this->upload->do_upload())
{
echo $this->upload->display_errors();
}
else {
$this->db->insert("tbl_pengadaan",$in);
?>
<script>
window.parent.location.reload(true);
</script>
<?php
}
}
Views (Lampiran's Form) :
<label class="control-label" for="nama_hukuman">File Lampiran</label>
<div class="controls">
<input type="file" name="userfile">
</div>
after i ran my code above, it shown warning like this :
A PHP Error was encountered
Severity: Notice
Message: Undefined index: userfile
Filename: controllers/dashboard_admin.php
Line Number: 279
file attachment can't uploaded and what i want is after uploading the file, file names automatically saved with unique number in database sql, for make user download list..
if there any advice, please, thanks..