CodeIgniter Forums
validation file uploadin - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: validation file uploadin (/showthread.php?tid=67987)



validation file uploadin - Ali - 05-05-2017

Hello everybody
i am building a simple help system with codeigniter. and users can attachment files when response to a ticket.
But I do not know how to display error for users when uploading files has problem encountered in view tickets. please check my code. i really need your help Heart

PHP Code:
public function show()
 
   {
 
       $show = array();
 
       $id $this->uri->segment('3');
 
       $groups_id $this->ticket_model->get_groups_id($id);
 
       $show['show_ticket'] = $this->ticket_model->show($id$groups_id);

 
       foreach ($show['show_ticket'] as $show_value){
 
           $show_gorup_id $show_value['department_id'];
 
           $create_by_id $show_value['user_id'];
 
       }

 
       $show['show_ticket_comment'] = $this->ticket_model->get_reply($id);

 
       foreach ($this->aauth->get_user_groups() as $user_groups) {
 
           $user_groups_id $user_groups->id;
 
       }

 
       if (($this->aauth->is_member('Admin')) ||($user_groups_id == $show_gorup_id) || ($create_by_id == $this->aauth->get_user_id())) {
 
           $this->template->load('ticket/show_ticket'$show);
 
       }else{
 
           echo 'Access Denied';
 
       }
 
   








public function 
reply()
 
   {
 
       $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);
 
       $this->upload->initialize($config);

 
      // if ( !$this->upload->do_upload('userfile')) {
 
        //   $error = array('error' => $this->upload->display_errors());
 
         //  $this->load->view('upload_form', $error);
 
          // return;
 
       //}

 
       $uploadData $this->upload->data();
 
       $file $uploadData['file_name'];


 
       $this->form_validation->set_rules('comment''Comment''required|trim');
 
       if ($this->form_validation->run() == FALSE) {
 
        //    $this->template->load('ticket/show_ticket',array('groups' => $ticket_add));
 
       //what code needs for display error here ?

 
       } else {
 
           $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;
 
           $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: validation file uploadin - InsiteFX - 05-05-2017

It shows you exactly how to do this in the CodeIgniter Users Guide - File_upload.


RE: validation file uploadin - Ali - 05-07-2017

(05-05-2017, 03:54 AM)InsiteFX Wrote: It shows you exactly how to do this in the CodeIgniter Users Guide - File_upload.

there is this line
$error = array('error' => $this->upload->display_errors());

 it doesn't work exactly for me. this is related to show function and i can't fix. please help me


RE: validation file uploadin - arisroyo - 05-07-2017

I always include the error message in backend through session and redirect back to previous page or controller and check if there's an error in session and display that to user.

You can also do it through json response Smile just an idea.