Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function uploadsound() {
- $user_info = $this->model->status('userData');
- $user_id = $user_info->id;
- $name = JRequest::getString('name');
- if($name == '') {
- echo json_encode(array('code' => 98, 'desc' => 'File name is not set' ));
- die;
- }
- $ext_array = explode(".", $name);
- $ext_array_count = count($ext_array);
- $extension = $ext_array[$ext_array_count-1];
- $name_orig = str_replace('.'.$extension, '', $name);
- $name_orig = str_replace(" ", "_", $name_orig);
- $name_new = $name_orig;
- $file_base64 = explode(',',JRequest::getString('value'));
- $file_binary = base64_decode($file_base64[1]);
- if($name_new != '' && $extension != '') {
- file_put_contents(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension, $file_binary);
- }
- if(!file_exists(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension)) {
- echo json_encode(array('code' => 99, 'desc' => 'File not uploaded' ));
- die;
- }
- // Upload file via API
- $ret = $this->model->uploadSound(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension);
- // Delete file from server
- unlink(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension);
- // Output JSON
- echo json_encode($ret);
- $this->_display('uploadsound');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement