Assalamualaikum Warahmatullahi Wabarakatuh...
Saya sedang membuat sebuah form komentar terhadap pengaduan masyarakat. Namun saya mengalami kendala saat upload berkas, sedangkan untuk tanggapan (komentar) terhadap pengaduan berhasil saya insert ke database. Adapun script yang telah saya tulis adalah sebagai berikut :
# v_komentar (View)
<form method="post">
<div class="form-group">
<div class="col-sm-12">
<label>Tanggapan</label>
<input class="form-control" id="komentar" name="komentar" type="text">
<?php echo form_error('komentar', '<span class="error">', '</span>'); ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label class="label-name">Berkas Balasan</label>
<input class="form-control " type="file" name="bls_berkas">
</div>
</div>
<button type="submit" class="btn btn-primary">Simpan</button>
<button class="btn" value="cancel" onclick="history.back();">Cancel</button>
</form>
# Pengaduan (Controller)
<?php
class Pengaduan extends CI_Controller{
function __construct(){
parent::__construct();
if($this->session->userdata('masuk') !=TRUE){
$url=base_url('administrator');
redirect($url);
};
$this->load->model('M_pengaduan','m_pengaduan');
$this->load->library('upload');
$this->load->library('datatables');
}
function komentar($id){
$x['pengaduan']=$this->m_pengaduan->get_all_pengaduan();
$data['pengaduan'] = $this->m_pengaduan->read('pengaduan');
$komentar=$this->input->post("komentar");
$this->db->query("update pengaduan set komentar='$komentar' WHERE id='$id'");
{
$this->load->helper(array('form', 'url'));
$config['upload_path'] = './assets/pengaduan/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['encrypt_name'] = TRUE;
$this->upload->initialize($config);
if ($this->upload->do_upload('bls_berkas')){
$gbr = $this->upload->data();
$config['image_library']='gd2';
$config['source_image']='./assets/pengaduan/'.$gbr['file_name'];
$config['create_thumb']= FALSE;
$config['maintain_ratio']= FALSE;
$config['quality']= '50%';
$config['width']= 600;
$config['height']= 400;
$config['new_image']= './assets/pengaduan/'.$gbr['file_name'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
(
'bls_berkas' => $gbr['file_name'],
);
$id = $this->m_pengaduan->update('pengaduan', $data);
echo "<script>alert('Insert Data Berhasil.');</script>";
redirect('/','refresh');
}
else
{
echo "Image yang diupload kosong";
$this->load->view('admin/v_komentar',$data);
}
}
}
Terimakasih sebelumnya kepada Admin dan teman2 di forum ini.