Associate
Does anyone have much experience with Bonfire? Just i'm having a problem using a callback to upload a file, and not getting any responses from either the bonfire & codeigniter forums.
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;
}
}
// 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;