Welcome Guest, Not a member yet? Register   Sign In
Update Image
#1

(This post was last modified: 11-13-2021, 05:57 AM by jreklund.)

Hey friend i cannot update the user image. it overwrites the old image.
please any hint regarding this problem?
thanks Smile
PHP Code:
public function edit($id=""){
$this->rbac->check_operation_access(); // Check auth

        if($this->input->post('submit')){
                $this->form_validation->set_rules('name''Name''trim|required|min_length[5]');
                $this->form_validation->set_rules('surname''Surname''trim|required');
                
                
if ($this->form_validation->run() == FALSE) {
                    $data = array(
                        'errors' => validation_errors()
                    );
                    $this->session->set_flashdata('errors'$data['errors']);
                    redirect(base_url('users/edit/'$id['user_id']));

                } else {

                    //$image = null;

                    if ($_FILES['image_thumb']['name']){

                        $config['upload_path']          './uploads/user_image/';
                        $config['allowed_types']        'gif|jpg|png|jpeg|JPEG|GIF|JPG|PNG';
                        $config['max_size']            "1024";
                        $config['max_width']            "*";
                        $config['max_height']          "*";
                        $config['encrypt_name']        TRUE;
                        $this->upload->initialize($config);
                        $this->load->library('upload'$config);
                        if ( ! $this->upload->do_upload('image_thumb')){

                            $this->session->set_userdata(array('errors'=> $this->upload->display_errors()));
                            redirect(base_url('users/edit/'.$id['user_id']));
                        
                        
} else {
                            $image =$this->upload->data();
                            $image_url "uploads/user_image/".$image['file_name'];

                            //delete old image
                            $old_image $this->input->post('old_image');
                            $old_file_thumb =  substr($old_imagestrrpos($old_image'/') + 1);
                            @unlink(FCPATH 'uploads/user_image/' $old_file_thumb);

                        }
                    }

                    $old_image $this->input->post('old_image');

                    $data = array(
                        'image'        => (!empty($image_url) ? $image_url $old_image), 
Reply
#2

> i cannot update the user image. it overwrites the old image.

If the old image is overwritten, it seems you can update the user image.
I don't get what you say correctly.

See https://codeigniter.com/userguide3/libra...ading.html
and try a simple code first.
Reply
#3

If your change an image and want to create an updated image then you first need to save the orginal image.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(11-13-2021, 01:44 AM)InsiteFX Wrote: If your change an image and want to create an updated image then you first need to save the orginal image.

Hello
The firrst one is saved on db, and is loaded in the value, the overwrite of the image doesnt work

<div class="mt-3">
                                <label class="form-label">Image</label>
                                <input class="form-control" name="image_thumb" id="image_thumb" type="file">
                                <img alt="img pic" class="rounded-md" src="<?php echo base_url() . $row['image']; ?>">
                                <input class="form-control" name="old_image" id="old_image" type="hidden" value="<?php echo $row['image'];?>">
        </div>
Reply
#5

Are you using form open and form close? Without those it will never return anything to the controller post data.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(11-15-2021, 02:33 AM)InsiteFX Wrote: Are you using form open and form close? Without those it will never return anything to the controller post data.

Yes sure :

        <?php echo form_open(base_url('product/edit/'.$row['id']), 'class="form-horizontal"');  ?>

       //Code for edit product

      <?php echo form_close(); ?>
Reply
#7

https://codeigniter.com/userguide3/libra...references

The default value of overwrite is false.
Reply
#8

Still no result,
I added $config['overwrite']    = false; as @kenjis say but still the first image is displayed even after the replace Sad
if ($_FILES['image_thumb']['name']) {
                        $config['upload_path'] = './uploads/product_image/';
                        $config['allowed_types'] = 'gif|jpg|png|jpeg|JPEG|GIF|JPG|PNG';
                        $config['max_size'] = "1024";
                        $config['max_width'] = "*";
                        $config['max_height'] = "*";
                        $config['encrypt_name'] = TRUE;
                        $config['overwrite']    = false;
Reply




Theme © iAndrew 2016 - Forum software by © MyBB