Я хочу загрузить несколько изображений в базу данных на основе category_id и vendor_id , включая проверку с использованием Code-igniter. Вот скриншот
Скриншот прикрепления почтальона
function upload_category_doc(){
$vendor_id = $this->input->post("vendor_id");
$category_id = $this->input->post("category_id");
$response = array();
if(isset($_FILES['category_doc']['name']) && $_FILES['category_doc']['name'] !=''){
$insertArr['category_doc']=$this->cat_upload('category_doc');
}
$result = $this->providerapp_model->update_data("vbs_vendor_categories",$insertArr,array('vendor_id'=>$vendor_id,'category_id'=>$category_id));
$fields = "category_id,vendor_id,category_doc";
$sql1 = "SELECT $fields FROM vbs_vendor_categories vvc WHERE vvc.vendor_id=$vendor_id AND vvc.category_id=$category_id";
$vendor_cat_data = $this->db->query($sql1)->row();
if($result){
$response['data'] = $vendor_cat_data;
$response['status'] = "success";
$response['message'] = "Category document update successfully";
}else{
$response['status'] = "fail";
$response['message'] = "Something went wrong";
}
}
и его функция загрузки для загрузки документа категории
function cat_upload($imagename){
$date = date('His');
$config['upload_path'] = 'uploads/category_doc';
$config['file_name'] = 'category_doc' . $date;
$config['allowed_types'] = 'jpg|png|bmp|pdf|doc|svg';
$this->load->library('upload',$config);
if (!$this->upload->do_upload($imagename)) {
$upload_error = array('error' => $this->upload->display_errors());
} else {
$upload_data = $this->upload->data();
$config['image_library'] = 'gd2';
$config['source_image'] = $this->upload->upload_path . $this->upload->file_name;
$config['new_image'] = $this->upload->upload_path . "/thumb/" . $this->upload->file_name;
$config['master_dim'] = 'auto';
$config['width'] = 200;
$config['height'] = 200;
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$this->image_lib->resize();
return $upload_data['file_name'];
}
}