Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function add()
- {
- $this->form_validation->set_rules('sku', 'Sku', 'required');
- $this->form_validation->set_rules('name', 'Name', 'required');
- $this->form_validation->set_rules('price', 'Price', 'required');
- // $this->form_validation->set_rules('file_upload_manual_slike', 'Images', 'optional');
- $data['title'] = "adding";
- if ($this->form_validation->run() === FALSE)
- {
- $this->load->view('templates/header', $data);
- $this->load->view('templates/sidebar');
- $this->load->view('admin/produkt/product_form');
- $this->load->view('templates/footer');
- }
- else
- {
- $data['uspeh'] = "Success!";
- $this->produkt_model->dodaj_produkt();
- //$this->load->view('admin/produkt/product_form',$data);
- redirect($this->config->item('base_url'), 'refresh');
- $this->do_upload($this->db->insert_id());
- }
- }
- function do_upload($id_produkta)
- {
- $file_element_name = "file_upload_manual_slike";
- if ($status != "error")
- {
- $config['upload_path'] = './files/';
- $config['allowed_types'] = 'gif|jpg|png|doc|txt';
- $config['max_size'] = 1024 * 8;
- $config['encrypt_name'] = TRUE;
- $this->load->library('upload', $config);
- if (!$this->upload->do_upload($file_element_name,$id_produkta))
- {
- $status = 'error';
- $msg = $this->upload->display_errors('', '');
- }
- else
- {
- $data = $this->upload->data();
- $file_id = $this->produkt_model->dodaj_sliko($data['file_name']);
- if($file_id)
- {
- $status = "success";
- $msg = "File successfully uploaded";
- }
- else
- {
- unlink($data['full_path']);
- $status = "error";
- $msg = "Something went wrong when saving the file, please try again.";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement