1

I try to upload a file with code igniter but i get the error You did not select a file to upload.. Anyone knows how to resolve this? my var_dump shows this:

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

my controller

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

my view

<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 Answers 2

1

First of all you are using codeigniter and your form action is empty. don't know how your data reach to controller

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

change your form tag to codignitor standers and try

echo form_open_multipart('controller/function');
Sign up to request clarification or add additional context in comments.

Comments

0

The line:

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

The parameter for the do_upload function is expecting the name of the file upload field, so you should change it to:

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

1 Comment

Check the max_upload_size value in your php.ini file. It might be that the image you are trying to upload is larger than the maximum allowed size

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.