Edit upload Image Codeigniter 3

Selamat Pagi ... ada yang bisa bantu saya mengatasi masalah gagal edit upload image di codeigniter 3? saya mencoba membuat function edit upload image tp selalu gagal.

ini controller nya :


public function updateGambar($id_monitoring)
    {
        $this->form_validation->set_rules('keterangan_gambar_monitoring', 'Keterangan Gambar', 'required');

        if ($this->form_validation->run() == FALSE) {
            $data['monitoring'] = $this->Monitoring_model->find($id_monitoring);
            $data['content'] = 'monitoring/form_foto_monitoring';
            $data['judul'] = 'Monitoring';
            $this->load->view('template/t_home', $data);
        } else {
            if ($_FILES['userfile']['name'] != '') {
                //form submit dengan gambar diisi
                //load uploading file library
                $config['upload_path'] = './uploads/monitoring/';
                $config['allowed_types'] = 'jpg|png';
                $config['max_size'] = '300'; //KB
                $config['max_width'] = '600'; //pixels
                $config['max_height'] = '400'; //pixels

                $this->load->library('upload', $config);

                if (!$this->upload->do_upload()) {
                    $data['monitoring'] = $this->Monitoring_model->find($id_monitoring);
                    $data['content'] = 'monitoring/form_foto_monitoring';
                    $data['judul'] = 'Monitoring';
                    $this->load->view('template/t_home', $data);
                } else {
                    $gambar = $this->upload->data();
                    $data_gambar = array(
                        'keterangan_gambar_monitoring' => set_value('keterangan_gambar_monitoring'),
                        'foto_gambar_monitoring' => $gambar['file_name']
                    );
                    $this->Monitoring_model->update($id_monitoring, $data_gambar);
                    redirect('Monitoring');
                }
            } else {
                //form submit dengan gambar dikosongkan
                $data_gambar = array(
                    'keterangan_gambar_monitoring' => set_value('keterangan_gambar_monitoring')
                );
                $this->Monitoring_model->update($id_monitoring, $data_gambar);
                redirect('Monitoring');
            }
        }
    }

Ini modal nya :


public function find($id_monitoring)
    {
        //Query mencari record berdasarkan ID-nya
        $hasil = $this->db->where('id_monitoring', $id_monitoring)
            ->limit(1)
            ->get('m_monitoring');
        if ($hasil->num_rows() > 0) {
            return $hasil->row();
        } else {
            return array();
        }
    }

    public function update($id_monitoring, $data_gambar)
    {
        //Query UPDATE FROM ... WHERE id=...
        $this->db->where('id_monitoring', $id_monitoring)
            ->update('m_monitoring', $data_gambar);
    }

dan ini view nya :


<?php
$id_monitoring = $monitoring->id_monitoring;
if ($this->input->post('is_submitted')) {
    $keterangan_gambar_monitoring = set_value('keterangan_gambar_monitoring');
} else {
    $keterangan_gambar_monitoring = $monitoring->keterangan_gambar_monitoring;
}
?>

<?= form_open_multipart('monitoring/updateGambar/' . $id_monitoring, ['class' => 'form-horizontal']) ?>

                            <label><code>*</code>Foto Gambar
                                Pekerjaan
                                (JPG/PNG)</label><br>

                            <input type="file" class="form-control" name="userfile">

                            <textarea class="form-control"
                                name="keterangan_gambar_monitoring"><?= $keterangan_gambar_monitoring ?></textarea>
                            <br>
                            <input type="hidden" name="is_submitted" value="1" />
                            <button type="submit" class="btn btn-default">Save</button>

                            <hr size="10px" align="left">

                            <?= form_close(); ?>

Terima Kasih.

avatar mohamadkhamdan(mohamadkhamdan)
@mohamadkhamdan(mohamadkhamdan)

1 Kontribusi 0 Poin

Dipost 1 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban