Php 如何在同一表单上上载不同的文件

Php 如何在同一表单上上载不同的文件,php,html,database,codeigniter,Php,Html,Database,Codeigniter,我尝试在同一表单上上传不同的文件。我想将我的文件添加到我的目录中,并将文件名添加到我的数据库中。我可以上传目录中的文件,但无法上传到数据库中 这是我的控制器 function tambahdata() { $this->load->view('vtambah_mastersub'); if ($this->input->post('submit')) { if (!empty($_FILES['picture']['name'])) {

我尝试在同一表单上上传不同的文件。我想将我的文件添加到我的目录中,并将文件名添加到我的数据库中。我可以上传目录中的文件,但无法上传到数据库中

这是我的控制器

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>

图画
PDF
这是我的错误


任何人都可以帮我解决这个问题,谢谢。看起来你的代码中有一些拼写错误 试试这个

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);
}

当然,问题是您的
$db->insert()
如何工作我在我的模型中完成了它是的,我可以看到
$this->db->insert('tbl_mastersub',$data)但它是如何工作的?它不工作,这就是为什么我在这里提问。因为当我键入该查询时。结果是这样的。