Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function attach_file() {
- $result = array('');
- if(!empty($_FILES['...'])) {
- $upload = $this->upload_data('log_spt_att_file', $upload_path, $filename);
- if(empty($upload['error'])){
- // insert db
- } else {
- // return error
- $result = $upload;
- }
- }
- echo json_encode($result);
- }
- public function upload_data($file_post, $upload_path, $filename, $allowed_types = NULL) {
- $config['upload_path'] = $upload_path;
- if(!file_exists($config['upload_path'])) {
- mkdir($config['upload_path']);
- }
- $config['allowed_types'] = 'xls|xlsx|csv|doc|docx|pdf|png|jpg|jpeg|ppt|pptx';
- $config['max_size'] = $this->config->item('max_upload');
- $config['overwrite'] = false;
- $config['file_name'] = $filename;
- if($allowed_types) {
- $config['allowed_types'] = $allowed_types;
- }
- $this->load->library('upload', $config);
- $this->upload->initialize($config);
- if (!$this->upload->do_upload($file_post)) {
- $result['error'] = $this->upload->display_errors();
- } else {
- $result = $this->upload->data();
- }
- return $result;
- }
Add Comment
Please, Sign In to add comment