我尝试在同一表单上上传不同的文件。我想将我的目录中的文件和文件名添加到我的数据库中。我可以在目录中上传文件但是在数据库中它不起作用。
这是我的控制器
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>
这是我的错误
任何人都可以帮我解决这个问题,谢谢
答案 0 :(得分:0)
您的代码中似乎存在一些拼写错误 试试这个
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);
}