function upload_files($type = 'all')
 {
     if (!empty($_FILES) && $this->input->post('token') == md5('unique_salt' . $this->input->post('timestamp'))) {
         $upload_dir = $this->input->post('upload_for');
         if (empty($upload_dir)) {
             $upload_dir = $this->input->get('upload_for');
         }
         $upload_dirs = array('centre', 'child', 'lesson_record_material', 'sow_material', 'app_recommend', 'immunisations');
         if (!in_array($upload_dir, $upload_dirs)) {
             echo json_encode(array('status' => 'False', 'error' => 'Something went Wrong! Please Try again.'));
             return;
         }
         $config['upload_path'] = './uploads/' . $upload_dir . '/';
         switch ($type) {
             case 'images':
                 $config['allowed_types'] = 'jpg|jpeg|gif|png';
                 $config['max_size'] = '51200';
                 break;
             case 'immunisations':
                 $config['allowed_types'] = 'jpg|jpeg|pdf';
                 break;
             default:
                 $config['allowed_types'] = 'jpg|jpeg|gif|png|doc|docx|DOCX|ppt|pptx|xls|XLS|xlsx|XLSX|pdf|PDF|txt|avi|mpeg|swf|zip|mpeg|rv|mov|movie|mpg';
                 $config['max_size'] = '51200';
                 break;
         }
         $file_hash = get_file_name_hash();
         $config['file_name'] = $file_hash;
         //$file_hash;
         $this->load->library('upload', $config);
         if (!$this->upload->do_upload('Filedata')) {
             echo json_encode(array('status' => 'False', 'error' => $this->upload->display_errors()));
         } else {
             //'file_hash' => $file_hash,
             //'file_name' => $_FILES['Filedata']['name'],
             $upload_data = $this->upload->data();
             echo json_encode(array('status' => 'True', 'file_hash' => $file_hash, 'file_name' => $_FILES['Filedata']['name'], 'encoded_file_name' => rawurlencode($upload_data['file_name']), 'file_path' => base_url('uploads/' . $upload_dir . '/' . $upload_data['file_name']), 'image' => in_array(strtolower(file_extension($upload_data['file_name'])), array('jpg', 'jpeg', 'gif', 'png')) ? 'true' : 'false'));
         }
     } else {
         echo json_encode(array('status' => 'False', 'error' => 'Something went Wrong! Please Try again.'));
     }
 }
 public function uploadMissingChildImage()
 {
     $oldFileName = get_file_name_hash();
     $itemID = $this->input->post('itemID');
     $config['upload_path'] = './uploads/child/';
     $config['allowed_types'] = 'jpg|jpeg|gif|png';
     $config['max_size'] = '102400';
     $config['file_name'] = $oldFileName;
     $orginalName = $_FILES['file']['name'];
     $this->load->library('upload', $config);
     if (!$this->upload->do_upload('file')) {
         echo 'error : ' . $this->upload->display_errors();
     } else {
         $upload_data = $this->upload->data();
         $this->inspect_model->updateRow($itemID, array('missing_file' => 1, 'child_image_hash' => $oldFileName, 'image' => $orginalName), 'id', 'child_class');
         echo json_encode($orginalName . '#' . $upload_data['file_name']);
     }
     exit;
 }
 function upload_img()
 {
     if (!empty($_FILES) && $this->input->post('token') == md5('unique_salt' . $this->input->post('timestamp'))) {
         //$_FILES['Filedata']['name']
         $upload_dir = $this->input->post('upload_for');
         $upload_dirs = array('child', 'kins_image');
         if (!in_array($upload_dir, $upload_dirs)) {
             echo json_encode(array('status' => 'False', 'error' => 'Something went Wrong! Please Try again.'));
             return;
         }
         $hash = get_file_name_hash();
         $config['upload_path'] = './uploads/' . $upload_dir . '/';
         $config['allowed_types'] = 'jpg|jpeg|gif|png';
         $config['max_size'] = '102400';
         $config['file_name'] = $hash;
         $this->load->library('upload', $config);
         if (!$this->upload->do_upload('Filedata')) {
             echo json_encode(array('status' => 'False', 'error' => $this->upload->display_errors()));
         } else {
             $child_id = $this->input->post('child_id');
             $this->child_model->db->update(IMS_DB_PREFIX . 'child_class', array('image' => $_FILES['Filedata']['name'], 'child_image_hash' => $hash), array('id' => $child_id));
             $upload_data = $this->upload->data();
             $file = $hash . $upload_data['file_ext'];
             echo json_encode(array('status' => 'True', 'image_hash' => $hash, 'file_name' => $_FILES['Filedata']['name'], 'file_path' => base_url('uploads/' . $upload_dir . '/' . $file)));
         }
     } else {
         echo json_encode(array('status' => 'False', 'error' => 'Something went Wrong! Please Try again.'));
     }
     exit;
 }
 function upload_avatar()
 {
     if (!empty($_FILES) && $this->input->post('token') == md5('unique_salt' . $this->input->post('timestamp'))) {
         $upload_dir = $this->input->post('upload_for');
         $config['upload_path'] = './uploads/' . $upload_dir . '/';
         $config['allowed_types'] = 'jpg|jpeg|gif|png';
         $config['max_size'] = '102400';
         $file_name_hash = get_file_name_hash();
         $config['file_name'] = $file_name_hash;
         $this->load->library('upload', $config);
         if (!$this->upload->do_upload('Filedata')) {
             echo json_encode(array('status' => 'False', 'error' => $this->upload->display_errors()));
         } else {
             $upload_data = $this->upload->data();
             $file = $file_name_hash . $upload_data['file_ext'];
             echo json_encode(array('status' => 'True', 'file_name' => $upload_data['file_name'], 'org_file_name' => $_FILES['Filedata']['name'], 'file_hash' => $file_name_hash, 'file_path' => base_url('uploads/' . $upload_dir . '/' . $file)));
         }
     } else {
         echo json_encode(array('status' => 'False', 'error' => 'Something went Wrong! Please Try again.'));
     }
 }
Exemple #5
0
 function upload_files($type = 'all')
 {
     if (!empty($_FILES) && $this->input->post('token') == md5('unique_salt' . $this->input->post('timestamp'))) {
         $upload_dir = $this->input->post('upload_for');
         if (empty($upload_dir)) {
             $upload_dir = $this->input->get('upload_for');
         }
         $upload_dirs = array('centre', 'child', 'lesson_record_material', 'sow_material', 'album_item');
         if (!in_array($upload_dir, $upload_dirs)) {
             echo json_encode(array('status' => 'False', 'error' => 'Something went Wrong! Please Try again.'));
             return;
         }
         $config['upload_path'] = './uploads/' . $upload_dir . '/';
         $name = $_FILES['Filedata']['name'];
         $extention = strtolower(end(explode('.', $name)));
         //                 $name = preg_replace("/[ \-_]/", "", $name);
         //                 debug($name);
         $type1 = '';
         if (in_array($extention, array('jpg', 'jpeg', 'gif', 'png'))) {
             $config['allowed_types'] = 'jpg|jpeg|gif|png';
             $config['max_size'] = '1024';
             $type1 = 'image';
         } elseif (in_array($extention, array('avi', '3gp', 'mpeg', 'mov', 'mpg', 'mp4', 'wma', 'wmv'))) {
             $config['allowed_types'] = 'avi|mpeg|3gp|mov|mpg|mp4|wma|wmv';
             $config['max_size'] = '102400';
             $type1 = 'video';
         } elseif ($extention == 'zip') {
             $config['allowed_types'] = 'zip';
             $config['max_size'] = '51200';
             $type1 = 'zip';
         } else {
             $config['allowed_types'] = 'jpg|jpeg|gif|png|avi|zip|mpeg|mov|mpg|mp4|wma|wmv';
             $config['max_size'] = '51200';
         }
         $hash = get_file_name_hash();
         $config['file_name'] = $hash;
         $this->load->library('upload', $config);
         if (!$this->upload->do_upload('Filedata')) {
             echo json_encode(array('status' => 'False', 'type' => $type1, 'error' => $this->upload->display_errors()));
         } else {
             $upload_data = $this->upload->data();
             echo json_encode(array('status' => 'True', 'file_name' => $name, 'file_hash' => $hash, 'file_path' => base_url('uploads/' . $upload_dir . '/' . $upload_data['file_name'])));
         }
     } else {
         echo json_encode(array('status' => 'False', 'error' => 'Something went Wrong! Please Try again.'));
     }
 }