Advertisement
kartinamaslom26

Untitled

Jan 24th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. function uploadsound() {
  2.         $user_info = $this->model->status('userData');
  3.  
  4.         $user_id = $user_info->id;
  5.  
  6.         $name = JRequest::getString('name');
  7.  
  8.         if($name == '') {
  9.             echo json_encode(array('code' => 98, 'desc' => 'File name is not set' ));
  10.             die;
  11.         }
  12.  
  13.         $ext_array = explode(".", $name);
  14.  
  15.         $ext_array_count = count($ext_array);
  16.  
  17.         $extension = $ext_array[$ext_array_count-1];
  18.  
  19.         $name_orig = str_replace('.'.$extension, '', $name);
  20.  
  21.         $name_orig = str_replace(" ", "_", $name_orig);
  22.  
  23.         $name_new = $name_orig;
  24.  
  25.         $file_base64 = explode(',',JRequest::getString('value'));
  26.  
  27.         $file_binary = base64_decode($file_base64[1]);
  28.  
  29.         if($name_new != '' && $extension != '') {
  30.             file_put_contents(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension, $file_binary);
  31.         }
  32.  
  33.         if(!file_exists(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension)) {
  34.             echo json_encode(array('code' => 99, 'desc' => 'File not uploaded' ));
  35.             die;
  36.         }
  37.  
  38.         // Upload file via API
  39.         $ret = $this->model->uploadSound(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension);
  40.  
  41.         // Delete file from server
  42.         unlink(JPATH_COMPONENT.'/sound/'.$user_id.'/'.$name_new.".".$extension);
  43.  
  44.         // Output JSON
  45.         echo json_encode($ret);
  46.  
  47.         $this->_display('uploadsound');
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement