Update Image and Display

Simple way to upload multiple image upload view, edit and delete everything in codeigniter, this is one of the best way create a multiple image upload files with text also. Here i'm going to tell you a simple method for this multiple image upload and edit delete. Let see the step by step process and coding.



controller

 

         // ---------------------------Validation IMAGE-----------------------------
              if (empty($_FILES['product_image']['name']) && empty($product_id))
        {
                 $this->form_validation->set_rules('product_image','Product Image','required');
        }
        // ---------------------------Validation IMAGE END-----------------------------

 

$pack_data=$this->package_model->single($package_id);
        $current_pack_img=$pack_data->package_image;
        
        if ($this->form_validation->run())    // remove
        {


// ---------------------------UPLOAD IMAGE-----------------------------
       $config = [
        'upload_path'       => 'upload/package_image/',
        'allowed_types'     => 'gif|png|jpg|jpeg|PNG|JPG|JPEG|doc|docx|ppt|pdf|txt',
        'overwrite'         => false,
        'maintain_ratio'    => true,
        'encrypt_name'      => true,
        'remove_spaces'     => true,
        'file_ext_tolower'  => true
    ];
    $this->load->library('upload', $config);
    if ($this->upload->do_upload('package_image')) {  

        $data = $this->upload->data();
        $image = $config['upload_path'].$data['file_name'];

    }
        else{
        if(!empty($_FILES['package_image']['name'])){
           $error = array('error' => $this->upload->display_errors());
           $this->session->set_flashdata('exception',$this->upload->display_errors());
       }
                 
   }

   $userdata['package_image']=(!empty($image)?$image:$current_pack_img);
//echo "==========".$data['package']->package_image;die;
// ---------------------------UPLOAD IMAGE END-----------------------------


View Page

                        <div class="form-group row">
                        <label for="product_bv" class="col-sm-4 col-form-label">Package Image:</label>
                        <div class="col-sm-8">

                        <input type="file" id="package_image" class="form-control-file" name="package_image">
                     <br>
                             <?php if (!empty($package->package_image)) { ?>
                                <img src="<?php echo base_url().$package->package_image ?>" width="150" style='border-radius: 9px;'>
                             <?php } ?>  
                        </div>
                    </div>

model

    public function single($package_id = null)
    {
        return $this->db->select('*')
            ->from('package')
            ->where('package_id', $package_id)
            ->get()
            ->row();
    }

Our website uses cookies to enhance your experience. Learn More
Accept !