Ane lagi bikin form buat upload gambar gan, nama filenya udah kesimpen, tapi masih gagal buat nyimpen gambarnya...
ini script ane
Spoiler for controller:
public function proses_input(){
$data=array('judul'=>$this->input->post('judul'),
'gambar'=>$this->input->post('gambar'),
'isi'=>$this->input->post('isi'),
'tanggal'=>$this->input->post('tanggal'),
);
$this->capcin_model->insert($data);
redirect("index.php/capcin/input");
}
public function upload()
{
$this->load->view('capcin/admin/upload', array('error' => ' ' ));
}
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$data=array('judul'=>$this->input->post('judul'),
'gambar'=>$this->input->post('usaerfile'),
'isi'=>$this->input->post('isi'),
'tanggal'=>$this->input->post('tanggal'),
);
$this->capcin_model->insert($data);
$file_data = $this->upload->data();
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('capcin/admin/input', $error);
}
else
{
$data['img']=base_url().'/uploads/'.$file_data['file_name'];
$this->load->view('sukses', $data);
}
}
Spoiler for yang d view:
<?php echo form_open('index.php/capcin/proses_input'); ?>
<center>
<h3>Tambah Data</h3>
<table>
<tr>
<td width="100px">Judul</td>
<td>:</td>
<td>
<input type="text" name="judul" value="<?php set_value('judul')?>"></td>
</tr>
<tr>
<td width="100px">Isi</td>
<td>:</td>
<td>
<textarea name="isi" style="width:300px; height:200px;" value="<?php set_value('isi')?>"></textarea>
</td>
</tr>
<tr>
<td>Tanggal</td>
<td>:</td>
<td>
<input type="text" id="datepicker" name="tanggal" value=""/>
</td>
</tr>
<tr>
<td>Upload gambar</td>
<td>:</td>
<td>
<input type="file" name="gambar" size="20" />
</td>
</tr>
<tr><td colspan=4>----------------------------------------------</td></tr>
<tr>
<td colspan=2><input type="submit" value="Submit"></td>
<td colspan=2><input type="reset" value="Reset"></td>
</tr>
</table>
</center>
<?php echo form_close(); ?>
Help gan....