【发布时间】:2016-03-24 09:15:48
【问题描述】:
我尝试在同一个表单上上传不同的文件。我想将我的文件添加到我的目录中,并将文件名添加到我的数据库中。我可以在目录中上传文件,但到数据库中它不起作用。
这是我的控制器
function tambahdata()
{
$this->load->view('vtambah_mastersub');
if ($this->input->post('submit')) {
if (!empty($_FILES['picture']['name'])) {
$config['upload_path'] = './assets/uploads';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '40000';
$config['max_width'] = '1288';
$config['max_height'] = '1288';
$config['file_name'] = "file_" . time();
$this->load->library('upload');
$this->upload->initialize($config);
// if there was an error, return and display it
if (!$this->upload->do_upload('picture')) {
echo "errornya : ";
echo $this->upload->display_errors();
} else {
echo "sukses";
$gbr = $this->upload->data();
$data = array(
'nm_gbr' => $gbr['file_name'],
'tipe_gbr'=>$gbr['file_type'],
) ;
}
}
if (!empty($_FILES['pdf']['name'])) {
$config['upload_path'] = './assets/uploads';
$config['allowed_types'] = 'pdf';
$config['max_size'] = '40000';
$config['max_width'] = '1288';
$config['max_height'] = '1288';
$config['file_name'] = "file_" . time();
$this->load->library('upload');
$this->upload->initialize($config);
// if there was an error, return and display it
if (!$this->upload->do_upload('pdf')) {
echo "errornya : ";
echo $this->upload->display_errors();
} else {
echo "sukses";
$pdf = $this->upload->data();
$dataa = array(
'nm_pdf' => $pdf['file_name'],
'tipe_pdf' => $pdf['file_type'],
);
}
}
$this->m_mastersub->tambah($data,$dataa);
redirect('mastersub');
}
}
这是我的模特
function tambah($gambar,$pdf){
$kd_mastersub = $this->input->post('kd_mastersub');
$nama = $this->input->post('nama');
$picture = $gambar['nm_gbr'];
$deskripsi = $this->input->post('deskripsi');
$pdf = $pdf('nm_pdf');
$video = $gambar('nm_video');
$drive = $gambar('nm_drive');
$data = array(
'kd_mastersub' =>$kd_mastersub,
'name_cate' =>$nama,
'picture' => $picture,
'description' =>$deskripsi,
'pdf' => $pdf,
'video' => $video,
'drive' => $drive
);
$this->db->insert('tbl_mastersub',$data);
}
这是我的表格
<div class="row form-group">
<div class="col-md-6 text-left">
<label>Picture </label>
</div>
<div class="col-md-10 text-left">
<input type="file" name="picture" />
</div>
</div>
<div class="row form-group">
<div class="col-md-6 text-left">
<label>PDF </label>
</div>
<div class="col-md-10 text-left">
<input type="file" name="pdf" />
</div>
</div>
这是我的错误
谁能帮我解决这个问题,谢谢
【问题讨论】:
-
问题当然是你的
$db->insert()是如何工作的 -
我已经在我的模型中做到了
-
是的,我可以看到
$this->db->insert('tbl_mastersub',$data);,但它是如何工作的? -
它不起作用,这就是我在这里提问的原因。因为当我键入该查询时。结果是这样的。
标签: php html database codeigniter