CodeIgniter Forums
You did not select a file to upload. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: You did not select a file to upload. (/thread-68051.html)



You did not select a file to upload. - Ali - 05-17-2017

Hello
when i don't select any file for upload i will get that error!
i don't want file uploading be require field! how to disable ?

PHP Code:
   public function reply()
 
   {
 
       $this->form_validation->set_rules('comment','Comment','required|trim');
 
       $ticket_id $this->input->post('ticket_id');

 
       if($this->form_validation->run() == FALSE){
 
           $error_msg_reply 'پر کردن شرح درخواست الزامی می باشد';
 
           $error_msg_reply $this->session->set_flashdata('key',$error_msg_reply);
 
           //$show['show_ticket_comment'] = $this->ticket_model->get_reply($ticket_id);
 
           redirect('ticket/show/'.$ticket_id);
 
       }else{
 
           $config['upload_path'] = './file_ticket';
 
           $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|docx|txt';
 
           $config['max_size'] = 4000;
 
           $config['max_width'] = 11024;
 
           $config['max_height'] = 7168;
 
           $this->load->library('upload'$config);
 
           if(empty($_FILES['userfile'])) {
 
               $reply_ticket['file'] = 'Null';
 
           }else{
 
               $uploaded $this->upload->do_upload('userfile');
 
               if (!$uploaded) {
 
                   $error_msg_reply .= $this->upload->display_errors();
 
                   $this->session->set_flashdata('key',$error_msg_reply);
 
                   redirect('ticket/show/'.$ticket_id);
 
               } else {
 
                   $upload_data $this->upload->data();
 
                   $file_name $upload_data['file_name'];
 
               }
 
           }
 
                   $reply_ticket['ticket_comment_id'] = '';
 
                   $reply_ticket['ticket_id'] = $this->input->post('ticket_id');
 
                   $reply_ticket['user_id'] = $this->aauth->get_user_id();
 
                   $reply_ticket['comment'] = $this->input->post('comment');
 
                   $reply_ticket['create_date'] = now();
 
                   $reply_ticket['file'] = $file_name;
 
                   $insert_ticket_comment $this->ticket_model->reply($reply_ticket);
 
                   if ($insert_ticket_comment){
 
                       $show = array();
 
                       $id $this->input->post('ticket_id');
 
                       $groups_id $this->ticket_model->get_groups_id($id);
 
                       $show['show_ticket'] = $this->ticket_model->show($id$groups_id);
 
                       redirect('ticket/show/'.$id);
 
                   }
 
           }
 
       



RE: You did not select a file to upload. - InsiteFX - 05-17-2017

Check your $error_msg_reply if it is equal to ( 'upload_no_file_selected' )

That is the error message returned, use an if else statement to check for it.


RE: You did not select a file to upload. - Rufnex - 05-17-2017

You can make a condition check like:

Code:
if ($this->upload->do_upload('userfile'))
{
    $upload_data = $this->upload->data();
    # upload logic ...
}



RE: You did not select a file to upload. - ivantcholakov - 05-17-2017

I use this detection of whether a file is going to be uploaded, it always works:

Code:
$field = 'userfile'; // The name attribute of the file input control.
$file_selected = isset($_FILES[$field]) && isset($_FILES[$field]['name']) && $_FILES[$field]['name'] != '';