猿问

在 API Postman 的 codeigniter 中使用 db id 验证上传多张图片

我想根据category_idvendor_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());

    } 

    }


}


沧海一幻觉
浏览 165回答 2
2回答

拉风的咖菲猫

$setting = $this->image_settings();$this->load->library('upload', $setting);$total = count(@$_FILES['image']['name']);for($i=0; $i<$total; $i++){&nbsp; &nbsp; $_FILES['userfile']['name']= @$_FILES['image']['name'][$i];&nbsp; &nbsp; $_FILES['userfile']['type']= @$_FILES['image']['type'][$i];&nbsp; &nbsp; $_FILES['userfile']['tmp_name']= @$_FILES['image']['tmp_name'][$i];&nbsp; &nbsp; $_FILES['userfile']['error']= @$_FILES['image']['error'][$i];&nbsp; &nbsp; $_FILES['userfile']['size']= @$_FILES['image']['size'][$i];&nbsp; &nbsp; $this->upload->initialize($setting);&nbsp; &nbsp; $this->upload->do_upload();&nbsp; &nbsp; $actual_image_data = $this->upload->data();&nbsp; &nbsp; if(!empty($actual_image_data['is_image'])) {&nbsp; &nbsp; &nbsp; &nbsp; @$final_files_data[] = $actual_image_data['file_name'];&nbsp; &nbsp; &nbsp; &nbsp; $img_data['image_path'] = @$final_files_data[$i];&nbsp; &nbsp; &nbsp; &nbsp; $this->image_model->insert_image($img_data);&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; $response = [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'status' => FALSE,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'message' => 'Invalid file uploaded',&nbsp; &nbsp; &nbsp; &nbsp; ];&nbsp; &nbsp; &nbsp; &nbsp; die(json_encode($response));&nbsp; &nbsp; }}

温温酱

你可以在 postman 的 name 字段中添加一个 file_name[] ,你可以从那里选择多个文件你必须通过你的 PHP 代码循环上传的文件foreach ($_FILES['fil_name'] as $key => $value) {&nbsp; &nbsp; // your stuff}
随时随地看视频慕课网APP
我要回答