簡體   English   中英

文件上傳錯誤codeigniter

[英]file upload error codeigniter

我嘗試使用代碼igniter上載文件,但出現錯誤您未選擇要上載的文件。有人知道如何解決此問題嗎? 我的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>

首先,您正在使用codeigniter,並且表單action is empty 不知道您的數據如何到達控制器

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

將您的表單標簽更改為codignitor standers並嘗試

echo form_open_multipart('controller/function');

該行:

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

do_upload函數的參數需要文件上載字段的名稱,因此您應該將其更改為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM