文件上传错误codeigniter

时间:2015-04-30 10:12:45

标签: php codeigniter html-form

我尝试使用代码点火器上传文件,但我收到错误您没有选择要上传的文件..任何人都知道如何解决这个问题?我的var_dump显示了这个:

array(14) {
  ["file_name"]=> string(0) ""
  ["file_type"]=> string(0) ""
  ["file_path"]=> string(25) "./assets/profilepictures/"
  ["full_path"]=> string(25) "./assets/profilepictures/"
  ["raw_name"]=> string(0) ""
  ["orig_name"]=> string(0) ""
  ["client_name"]=> string(0) ""
  ["file_ext"]=> string(0) ""
  ["file_size"]=> NULL
  ["is_image"]=> bool(false)
  ["image_width"]=> NULL
  ["image_height"]=> NULL
  ["image_type"]=> string(0) ""
  ["image_size_str"]=> string(0) ""
}

我的控制器

if ($this->input->server('REQUEST_METHOD') == 'POST') {
   $id = $this->input->post('id_gids');

   $config['upload_path'] = './assets/profilepictures/';
   $config['allowed_types'] = 'gif|jpg|png|jpeg';
   $config['max_size']    = '100000000';
   $config['overwrite'] = TRUE;
   $config['remove_spaces'] = TRUE;
   $config['encrypt_name'] = FALSE;

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

   $image_path = $this->upload->data();
   $gidsimg = $image_path["file_name"];

   var_dump($image_path);
   var_dump($this->upload->display_errors());

   $data = array(
     'gids_name' => $this->input->post('voornaam'),
     'gids_surname' => $this->input->post('name'),
     'gids_city' => $this->input->post('stad'),
     'gids_email' => $this->input->post('mail'),
     'gids_password' => $this->input->post('password'),
     'gids_bio' => $this->input->post('bio'),
     'gids_year' => $this->input->post('jaar'),
     'gids_interest' => $this->input->post('studie'),
     'gids_picture' => "assets/profilepictures/".$gidsimg
   );

   $this->Mod_model->update($id, $data);
}

我的观点

<form action="" method="post" enctype="multipart/form-data">
  <input type="hidden" name="id_gids" value="<?php echo $w['gids_id'] ?>"/>
  <div class="pictureprofile">
    <img src="../../<?php echo $w['gids_picture'] ?>" alt="Profile Picture" class="profilepicture">
  </div><br>
  <input type="file" name="gids_img"/><br/>
</form>

2 个答案:

答案 0 :(得分:1)

首先,您使用的是codeigniter和表单action is empty。不知道您的数据如何到达控制器

<form action="" method="post" enctype="multipart/form-data">

将表单标记更改为codignitor standers并尝试

echo form_open_multipart('controller/function');

答案 1 :(得分:0)

该行:

$this->upload->do_upload('file');

do_upload函数的参数是期望文件上载字段的名称,因此您应该将其更改为:

$this->upload->do_upload('gids_img');