duanmen8491 2017-08-11 10:02
浏览 20

codeigniter中的图片上传失败

I have a problem with inserting data when the button is submitted, the image upload fails.

I tried several times but failed. how to upload images successfully and stored so here my code:

My controller:

public function savedosen() {

    $this->load->library('upload');
    $config['upload_path'] = './images/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
    $config['max_size'] = '2048';
    $config['max_width']  = '1288';
    $config['max_height']  = '768';

$this->upload->initialize($config);

if ($this->upload->do_upload('foto')) 
{
    $gambar = $this->upload->data();
    $nik       = $this->input->post('nik');
    $nama      = $this->input->post('nama_dosen');
    $jk  = $this->input->post('jk');
    $agama  = $this->input->post('agama');
    $tempat  = $this->input->post('tempat');


    $title  = $this->input->post('title');
    $status  = $this->input->post('status');
    $prodi  = $this->input->post('prodi');
    $password  = $this->input->post('confirm_password');
     $data = array(
        'nik_dosen'     =>$nik,
        'nama_dosen'    => $nama,
        'jenis_kelamin' => $jk,
        'agama'         => $agama,
        'tempat_lahir'  =>$tempat,

        'status'        => $status,
        'title_dosen'   => $title,
        'foto_dosen'    => $gambar['file_name'],
        'pass_dosen'    => md5($password),
        'id_prodi'      => $prodi,

    );
    $this->dosen_model->insertdosen($data);

    redirect('dosen');

}
else
{
    echo "Gagal";
}}

My view:

<div class="form-group ">
                                      <label for="firstname" class="control-label col-lg-2">Upload Gambar
                                      <span class="required"> * </span></label>
                                      <div class="col-lg-6">
                                          <input class=" form-control" id="foto" name="foto" type="file"  />
                                      </div>
                                  </div>

Help me to resolve it.

  • 写回答

1条回答 默认 最新

  • doulian7305 2017-08-11 11:45
    关注

    change

    $this->load->library('foto');
    

    to

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

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据