nebukad

upload_ci

Feb 8th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. public function attach_file() {
  2.     $result = array('');
  3.     if(!empty($_FILES['...'])) {
  4.  
  5.         $upload = $this->upload_data('log_spt_att_file', $upload_path, $filename);
  6.  
  7.         if(empty($upload['error'])){
  8.             // insert db
  9.         } else {
  10.             // return error
  11.             $result = $upload;
  12.         }
  13.     }
  14.  
  15.     echo json_encode($result);
  16. }
  17.  
  18.  
  19. public function upload_data($file_post, $upload_path, $filename, $allowed_types = NULL) {
  20.     $config['upload_path'] = $upload_path;
  21.     if(!file_exists($config['upload_path'])) {
  22.         mkdir($config['upload_path']);
  23.     }
  24.     $config['allowed_types'] = 'xls|xlsx|csv|doc|docx|pdf|png|jpg|jpeg|ppt|pptx';
  25.     $config['max_size'] = $this->config->item('max_upload');
  26.     $config['overwrite'] = false;
  27.     $config['file_name'] = $filename;
  28.  
  29.     if($allowed_types) {
  30.         $config['allowed_types'] = $allowed_types;
  31.     }
  32.  
  33.     $this->load->library('upload', $config);
  34.     $this->upload->initialize($config);
  35.  
  36.     if (!$this->upload->do_upload($file_post)) {
  37.         $result['error'] = $this->upload->display_errors();
  38.     } else {
  39.         $result = $this->upload->data();
  40.     }
  41.  
  42.     return $result;
  43. }
Add Comment
Please, Sign In to add comment