upload gambar tidak terupdate dan tidak ada perintah error tetapi sukses

 public function edit()
    {
        $this->form_validation->set_rules('username', 'Full name', 'required|trim');
        $this->form_validation->set_rules('address', 'Address', 'required|trim');
        if ($this->form_validation->run() == false) {
            $data = array(
                'title'          => 'Edit Profile',
                'titelbar'       => 'WEB SHS',
                'isi'            => 'user/edit'
            );
            $data['user'] = $this->db->get_where('user', ['email' =>
            $this->session->userdata('email')])->row_array();
            $this->load->view('admin/layout/v_wrapper', $data);
        } else {
            $username = $this->input->post('username');
            $address = $this->input->post('address');
            $email = $this->input->post('email');
            //jika ada gambar yang di upload
            $upload_image = $_FILES['image']['name'];
            if ($upload_image) {
                $config['allowed_types'] = 'jpg|png';
                $config['max_size']     = '2048';
                $config['upload_path'] = './assets/img/profile/';

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

                if ($this->upload->do_upload('image')) {
                    $old_image = $data['user']['image'];
                    if ($old_image != 'default.jpg') {
                        unlink(FCPATH . 'assets/img/profile/' . $old_image);
                    }
                    $new_image = $this->upload->data('file-name');
                    $this->db->set('image', $new_image);
                } else {
                    echo $this->upload->display_errors();
                }
            }
            $this->db->set('username', $username);
            $this->db->set('address', $address);
            $this->db->where('email', $email);
            $this->db->update('user');
            $this->session->set_flashdata('massage', '<div class="alert alert-success" role="alert">
       Youre profile has bend update!</div>');
            redirect('user');
        }
    }
avatar pheotofficial_google

@pheotofficial_google

1 Kontribusi 0 Poin


Jawaban

itu sistem cache server, default nya biasa nya 7 hr

agar tampilan terupdate maka pada html mesti tiambah parameter file dinamik

misal pada html nya:

<img src="upload/img/filegambar1.jpg">


dirubah menjadi

<img src="upload/img/filegambar1.jpg?t=xx">

dimana xx bisa diganti ganti, yg paling baik ada filetime nya diambil dari php code:

filemtime("upload/img/filegambar1.jpg");

jadi codingnya:
<?php
$jamfile=filemtime("upload/img/filegambar1.jpg");
echo "<img src='upload/img/filegambar1.jpg?t=$jamfile'>";?>
avatar gurukoding

@gurukoding

20 Kontribusi 8 Poin


Login untuk gabung berdiskusi