Welcome Guest, Not a member yet? Register   Sign In
Bonfire upload
#1

[eluser]Unknown[/eluser]
Hi guys, I'm going to ask here as I'm getting no replies on the bonfire forums to an issue i'm having

What happens is the file uploads multiple times. 5 times actually.

Got any clues as to why it would be doing this?

Code:
private function save_products($type='insert', $id=0)
    {
        if ($type == 'update') {
            $_POST['id'] = $id;
        }


        $this->form_validation->set_rules('p_manufacturer','Manufacturer','required|trim|xss_clean|alpha_extra|max_length[100]');
        $this->form_validation->set_rules('p_product','Product Name','required|unique[bf_products.p_product,bf_products.id]|trim|xss_clean|alpha_extra|max_length[100]');
        $this->form_validation->set_rules('p_description','Description','required|trim|xss_clean');
        $this->form_validation->set_rules('p_photo', 'Photo', 'callback_handle_upload');
        $this->form_validation->set_rules('p_priceindex','Price Index','required|trim|xss_clean|alpha|max_length[5]');
        $this->form_validation->set_rules('p_price','Price','required|trim|xss_clean|alpha_extra|max_length[30]');
        $this->form_validation->set_rules('p_status','Status','trim|xss_clean|is_numeric|max_length[1]');

        if ($this->form_validation->run() === FALSE)
        {
            return FALSE;
        }

        // make sure we only pass in the fields we want

        $data = array();
        $data['p_manufacturer'] = $this->input->post('p_manufacturer');
        $data['p_product']      = $this->input->post('p_product');
        $data['p_description']  = $this->input->post('p_description');
        $data['p_photo']        = $_POST['p_photo']['name'];
        $data['p_thumb']       = $this->input->post('p_thumb');
        $data['p_priceindex']   = $this->input->post('p_priceindex');
        $data['p_price']        = $this->input->post('p_price');
        $data['p_slug']         = $this->products_model->create_unique_slug($this->input->post('p_manufacturer').'-'.$this->input->post('p_product'), 'bf_products');
        $data['p_created_on']   = date('Y-m-d H:i:s', time());
        $data['p_status']       = $this->input->post('p_status');

        if ($type == 'insert')
        {    

            $id = $this->products_model->insert($data);
            if (is_numeric($id))
            {
                $return = $id;
            } else
            {
                $return = FALSE;
            }
        }
        else if ($type == 'update')
        {
            if($this->input->post('p_photo')) {
                $product_data = array(
                        $this->input->post('current_product_image'),
                        $this->input->post('current_product_image_thumb')
                    );

                $imgs_result = $this->products_model->delete_images($product_data);
                if(!$imgs_result) {
                    Template::set_message(lang('products_delete_images') . $this->products_model->error, 'error');
                } else {
                    //$data['p_photo'] = $fdata['upload_data']['file_name'];
                    //$data['p_thumb'] = $fdata['thumb_data']['file_name'];
                }
            } else {
                //$data['p_photo'] = $this->input->post('current_product_image');
                //$data['p_thumb'] = $this->input->post('current_product_image_thumb');
            }
            $return = $this->products_model->update($id, $data);
        }
        //print_r($data);
        return $return;
    }




function handle_upload()
    {

            $config['upload_path'] = './assets/images/products/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '0';
            $config['remove_spaces']=TRUE;

            $this->load->library('upload', $config);

        if (isset($_FILES['p_photo']) && !empty($_FILES['p_photo']['name']))
          {
              if ($this->upload->do_upload('p_photo'))
              {

                $upload_data    = $this->upload->data();
                print_r($upload_data);
                $_POST['p_photo'] = $upload_data['file_name'];

                return true;
              }
              else
              {

                $this->form_validation->set_message('handle_upload', $this->upload->display_errors());
                return false;
              }
        }
        else
        {

          $this->form_validation->set_message('handle_upload', "You must upload an image!");
          return false;
        }
    }
#2

[eluser]Unknown[/eluser]
Anyone?.




Theme © iAndrew 2016 - Forum software by © MyBB