Codeigniter Bonfire

Associate
OP
Joined
5 Jun 2004
Posts
1,338
Location
Hythe, Hants
Ahh good. Basically what is happening is I'm using a callback to upload a file (like I said). However the file uploads 5 times!!!
If I set overwrite to true then it won't do it. But its probably because the file is being overwritten.

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 {
                    //$fdata = $this->savenew();
                    //$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;
        }
    }
 
Last edited:
Associate
OP
Joined
5 Jun 2004
Posts
1,338
Location
Hythe, Hants
Take it as a no. Perhaps if I post a picture of a cat I'll get more response from OcUK.

pic of cat, isn't he cute :D
dexter2.jpg
 
Associate
OP
Joined
5 Jun 2004
Posts
1,338
Location
Hythe, Hants
So 163 views, of which I assume 50 % are so that people can look at a kitten. Can anyone actually help?????

Ohh and the kittens name is Dexter, He's pretty cool tbh. Likes cuddles and chasing a laser pen. Eats quite a bit too!! Porky pig.
 
Last edited:
Associate
OP
Joined
5 Jun 2004
Posts
1,338
Location
Hythe, Hants
So, I eventually located the issue down to CI messing with the callback somehow and turned to look at the Form_validation class. Could not locate anything in there un-toward.

So took a look inside Bonfires libraries. Low and behold. MY_Form_validation. Comment this line out.

Code:
// Merged super-global $_FILES to $_POST to allow for better file validation inside of Form_validation library
$_POST = (isset($_FILES) && is_array($_FILES) && count($_FILES) > 0) ? array_merge($_POST,$_FILES) : $_POST;


And the issue resolves itself.

No more callbacks x 5!!
 
Back
Top Bottom