0

I am trying to upload image to the folder on the server and store another data in the databse from the same form simultaneously. But it is showing error You did not select a file to upload.

Below is my view and controller for the same:

View:

<form role="form" method="post" action="job_insert" enctype="multipart/form-data">
                        <div class="box-body">
                          <div class="form-group">
                              <label>Job Name*</label>
                              <input type="text" class="form-control" name="jname" placeholder="Enter Job Name" required>
                          </div>

                          <div class="form-group">
                            <label>Description</label>
                            <textarea rows="4" cols="10" class="form-control" name="description" required></textarea>
                          </div>
                          <div class="form-group">
                              <label>File input</label>
                            <input type="file" name="userimage">
                          </div>
                          <div class="form-group">
                      <label>Paper Size*</label>

                  <div class="form-group">
                    <label>Paper Cutting Size</label>  
                      <div>
                      <input id="cutting_size" name="cutting_size" type="text" placeholder="Cutting Size" class="form-control input-md" required>  
                    </div>
                  </div>
                  <div class="form-group">
                    <label>Sheet</label>  
                    <div>
                      <input id="sheet" name="sheet" type="text" placeholder="No. of Sheet" class="form-control input-md" required>
                      </div>
                  </div>
                  <div class="form-group">
                    <label>Tin No.</label>  
                    <div>
                      <input id="sheet" name="tin" type="text" placeholder="Tin No." class="form-control input-md" required>
                      </div>
                  </div>
                    </div>
          <!-- /.box-body -->
                    <div style="margin-left: 600px" class="box-footer">
                      <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </form>

Controller:

public function job_insert()
        {
            $this->form_validation->set_rules('jname', 'job_name', 'trim');
            if($this->form_validation->run()== FALSE)
            {
                $this->load->view('invalid_jobname');
            }
            else
            {
                $this->do_upload();

                $data = $_SESSION['email'];
                $id = $this->user_model->get_client_id($data);
                $data = array('cid' => $id,
                                'job_name' => $this->input->post("jname"),
                                'job_id' => $this->input->post("job_id"),
                                'description' => $this->input->post("description"),
                                'img_name' => $img_name,
                                'adate' => Date('Y-m-d'),
                                'status' => 'NEW',
                                'paper_size' => $this->input->post("paper_size"),
                                'paper_type' => $this->input->post("paper_type"),
                                'cutting_size'=> $this->input->post("cutting_size"),
                                'sheet'=> $this->input->post("sheet"),
                                'tin' => $this->input->post("tin"),
                                'lamination' => $this->input->post("checkboxes"),
                                'print_type' => $this->input->post("checkboxes1"),
                                'binding' => $this->input->post("checkboxes2"),
                                 );

                $query = $this->user_model->job_insert($data);
                if ($query == TRUE) 
                {
                    $this->load->view('job_submitted');
                }
                else
                {
                    $this->load->view('error_page');
                }

            }
        }

Here's my do_upload function:

public function do_upload()
    {
    $config = array(
                'upload_path' => "./uploads/",
                'allowed_types' => "gif|jpg|png|jpeg|pdf",
                'overwrite' => FALSE,
                'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
                'max_height' => "768",
                'max_width' => "1024"
                 );

                $this->load->library('upload', $config);
                $image = $this->input->post("image");
                echo $image;
                if(!$this->upload->do_upload('userimage'))
                {   
                    $error = $this->upload->display_errors();
                    echo $error;
                }
        }
4
  • you missed enctype in form and give the fullpath of method like controller/method Commented Aug 26, 2016 at 5:51
  • i have add enctype but it did not work Commented Aug 26, 2016 at 5:58
  • update your code .. Commented Aug 26, 2016 at 6:02
  • Thank you everyone for your efforts. Commented Aug 26, 2016 at 6:17

3 Answers 3

1

Change this to

<input type="file" name="image">

to

<input type="file" name="userfile"/>

and in do_upload

if(!$this->upload->do_upload())

to if ( ! $this->upload->do_upload('userfile'))

Sign up to request clarification or add additional context in comments.

2 Comments

great , it worked. Thank you so much. Can you give a reason why it was not happening with 'image'?
0

Provide enctype="multipart/form-data" in your form tag. Without it you cannot upload image.

Comments

0

update form tag with below code

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

Comments

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.