Welcome Guest, Not a member yet? Register   Sign In
You did not select a file to upload.
#1

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);
 
                   }
 
           }
 
       
Reply
#2

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 05-17-2017, 04:18 AM by Rufnex.)

You can make a condition check like:

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

Reply
#4

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'] != '';
Reply




Theme © iAndrew 2016 - Forum software by © MyBB