php - Codeigniter: how to edit form without edit image input -


i need small figure out edit page.

i have insert data , edit data.

on edit data requesting form file/image upload, , on submit send null column file/image.

what need on edit if no new file on file/image input skip input.

this controller insert , edit data.

// set form         $rules = $this->image_m->rules;         $this->form_validation->set_rules($rules);          // upload file image         $status = "";         $msg = "";         $file_element_name = 'file_name';          if ($status != "error")         {           $config['upload_path'] = './uploads/images/';           $config['allowed_types'] = 'gif|jpg|png|doc|txt';           $config['max_size']   = '2000';           $config['max_width']  = '1024';           $config['max_height']  = '768';           $config['encrypt_name'] = false;           $config['remove_spaces'] = true;            $this->load->library('upload', $config);            if (!$this->upload->do_upload($file_element_name))           {              $status = 'error';              $msg = $this->upload->display_errors('', '');           }           else             {              $image = $this->upload->data();              }           }            // process form         if ($this->form_validation->run() == true) {             $data = array(                 'pubdate' => $this->input->post('pubdate'),                 'enddate' => $this->input->post('enddate'),                 'name' => $this->input->post('name'),                 'image'     => $image['file_name']             );             $this->image_m->save($data, $id);             redirect('admin/image');         } 

any appreciated.

solution:

// process form         if ($this->form_validation->run() == true) {             if(is_null($image['file_name'])){             $data = array(                 'pubdate' => $this->input->post('pubdate'),                 'enddate' => $this->input->post('enddate'),                 'name' => $this->input->post('name'),                 'caption' => $this->input->post('caption')             );             } else {             $data = array(                 'pubdate' => $this->input->post('pubdate'),                 'enddate' => $this->input->post('enddate'),                 'name' => $this->input->post('name'),                 'image'     => $image['file_name'],                 'caption' => $this->input->post('caption')             );             } 

$img = null;  //check if file being uploaded/updated if($_files['fieldname'][tmp_name] != ''){    //upload file here.....     $file = $this->upload->data();    $img  = $file['file_name'];  }  //if no file name assigned var, use data stored in model //default_image.jpg if(is_null($img)) $img = (string)$model->image; 

-

`image` varchar(255) not null default 'default_image.jpg' 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -