繁体   English   中英

如何在同一表格上上传不同的文件

[英]how to upload different file on the same form

我尝试以相同的形式上传不同的文件。 我想将目录中的文件和文件名添加到数据库中。 我可以将文件上传到目录中,但是无法正常工作。

这是我的控制器

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>

这是我的错误

在此处输入图片说明

任何人都可以帮助我解决这个问题,谢谢

看起来您的代码中有一些错别字,请改试试

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM