我以两种格式上传了两种类型名称的图片
我创建了一个数据库tbl_gambar,其内容为: id |甘巴| ttd
控制器
public function hit_post(){
header('Content-Type: application/json');
$data = array(
'id' => $this->input->post('id'),
);
if (!empty($_FILES['gambar']) || (!empty($_FILES['tdd']))) {
$upload = $this->_do_upload();
$data['gambar'] = $upload; // image 1
$data['ttd'] = $upload; // image 2
}
$this->M_order->simpan_db_barang($data);
// $res = array(
// 'message' => 'sukses upload'
// );
// echo json_encode($res);
echo "<pre>";
print_r($data);
echo "</pre>";
}
public function _do_upload(){
$config['upload_path'] = './assets/img/race/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 10000;
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = TRUE;
$config['quality'] = '80%';
$config['width'] = 1000;
$config['height'] = 1000;
$config['new_image'] = './assets/img/race/'.$data["file_name"];
$config['file_name'] = round(microtime(true)*1000);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('gambar') || !$this->upload->do_upload('ttd') ) {
}
return $this->upload->data('file_name');
}
}
模型
public function simpan_upload($gambar,$ttd){
$hasil=$this->db->query("INSERT INTO tbl_gambar(gambar,ttd) VALUES ('$gambar','$ttd')");
return $hasil;
}
如何将图像正确放入数据库?