Advertisement
Guest User

Untitled

a guest
Aug 6th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. public function add()
  2.     {
  3.         $this->form_validation->set_rules('sku', 'Sku', 'required');
  4.         $this->form_validation->set_rules('name', 'Name', 'required');
  5.         $this->form_validation->set_rules('price', 'Price', 'required');
  6.     //  $this->form_validation->set_rules('file_upload_manual_slike', 'Images', 'optional');
  7.        
  8.        
  9.         $data['title'] = "adding";
  10.         if ($this->form_validation->run() === FALSE)
  11.         {
  12.             $this->load->view('templates/header', $data);  
  13.             $this->load->view('templates/sidebar');
  14.             $this->load->view('admin/produkt/product_form');
  15.             $this->load->view('templates/footer');
  16.            
  17.         }
  18.         else
  19.         {
  20.             $data['uspeh'] = "Success!";
  21.             $this->produkt_model->dodaj_produkt();
  22.             //$this->load->view('admin/produkt/product_form',$data);
  23.             redirect($this->config->item('base_url'), 'refresh');
  24.            
  25.             $this->do_upload($this->db->insert_id());
  26.         }
  27.     }
  28.  
  29.     function do_upload($id_produkta)
  30.     {
  31.         $file_element_name = "file_upload_manual_slike";
  32.         if ($status != "error")
  33.        {
  34.           $config['upload_path'] = './files/';
  35.           $config['allowed_types'] = 'gif|jpg|png|doc|txt';
  36.           $config['max_size']  = 1024 * 8;
  37.           $config['encrypt_name'] = TRUE;
  38.      
  39.           $this->load->library('upload', $config);
  40.      
  41.           if (!$this->upload->do_upload($file_element_name,$id_produkta))
  42.           {
  43.              $status = 'error';
  44.              $msg = $this->upload->display_errors('', '');
  45.           }
  46.           else
  47.           {
  48.              $data = $this->upload->data();
  49.              $file_id = $this->produkt_model->dodaj_sliko($data['file_name']);
  50.              if($file_id)
  51.              {
  52.                 $status = "success";
  53.                 $msg = "File successfully uploaded";
  54.              }
  55.              else
  56.              {
  57.                 unlink($data['full_path']);
  58.                 $status = "error";
  59.                 $msg = "Something went wrong when saving the file, please try again.";
  60.              }
  61.           }
  62.        }
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement