无法在 codeigniter 上上传图片或 pdf

我无法在我的 codeigniter 上上传图片或 pdf


这是我的看法


 <div class="form-group">

        <label>Upload Gambar</label>

        <input name="foto" type="file" class="form-control">

    </div>

这是我的控制器


 function form_pendaftaran_act(){

    $nik = $this->input->post('nik');

    $nama = $this->input->post('nama_anggota');

    $gender = $this->input->post('gender');

    $ttl = $this->input->post('ttl');

    $email = $this->input->post('email');

    $notelp = $this->input->post('notelp');

    $alamat = $this->input->post('alamat');

    $pendidikan = $this->input->post('pendidikan');

    $status = $this->input->post('status');

    $tinggi_badan = $this->input->post('tinggi_badan');

    $berat_badan = $this->input->post('berat_badan');

    $uk_baju = $this->input->post('uk_baju');

    $uk_celana = $this->input->post('uk_celana');

    $posisi = $this->input->post('posisi');


    $this->form_validation->set_rules('nama_anggota','Nama Anggota',

    'required');

    $this->form_validation->set_rules('email','Email','required');



   if($this->form_validation->run() != false){

      $config['upload_path'] = './assets/upload/';

      $config['allowed_types'] = 'jpg|png|jpeg|pdf';

      $config['max_size'] = '2048';

      $config['file_name'] = 'gambar'.time();


      $this->load->library('upload', $config);


      if($this->upload->do_upload('foto')){

        $image=$this->upload->data();


      $data = array(

        'nik' => $nik,

        'nama_anggota' => $nama,

        'gender' => $gender,

        'ttl' => $ttl,

        'email' => $email,

        'no_telp' => $notelp,

        'alamat' => $alamat,

        'pendidikan' => $pendidikan,

        'status' => $status,

        'tinggi_badan' => $tinggi_badan,

        'berat_badan' => $berat_badan,

        'uk_baju' => $uk_baju,

        'uk_celana' => $uk_celana,

        'posisi' => $posisi,

        'gambar' => $image['file_name']


         );


我的问题是我无法上传图片或 pdf。在我点击我的视图提交后,网络只看到一个空白的白色屏幕。但是,在我添加图像配置脚本之前,网络运行良好


温温酱
浏览 118回答 1
1回答

萧十郎

您必须确保表单具有指定的 enctype,否则不会上传任何文件。<form action="/route" method="post" enctype="multipart/form-data">&nbsp; &nbsp; <div class="form-group">&nbsp; &nbsp; &nbsp; &nbsp; <label>Upload Gambar</label>&nbsp; &nbsp; &nbsp; &nbsp; <input name="foto" type="file" class="form-control">&nbsp; &nbsp; </div></form>
打开App,查看更多内容
随时随地看视频慕课网APP