public function createFile(array $fileData) { $accessToken = $this->getAccessToken(); $mimeType = $fileData['mimeType']; $fileSrc = $fileData['src']; $fileName = $fileData['name']; CWebDavTools::convertToUtf8($fileName); $fileSize = $fileData['size'] ? $fileData['size'] : filesize($fileSrc); $content = file_get_contents($fileSrc); $http = new CHTTP(); $http->http_timeout = 10; $fileName = urlencode($fileName); $arUrl = $http->ParseURL("https://apis.live.net/v5.0/me/skydrive/files/{$fileName}?access_token=" . urlencode($accessToken)); if (!$http->Query('PUT', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $content, $arUrl['proto'], '')) { return false; } $this->checkHttpResponse($http); // error checking if ($http->status != '200' && $http->status != '201') { return false; } return json_decode($http->result, true); }
public static function sendJsonResponse($response, $httpStatusCode = null, $afterEchoCallback = null) { global $APPLICATION; $APPLICATION->restartBuffer(); while (ob_end_clean()) { } if ($httpStatusCode == 403) { header('HTTP/1.0 403 Forbidden', true, 403); } if ($httpStatusCode == 500) { header('HTTP/1.0 500 Internal Server Error', true, 500); } header('Content-Type:application/json; charset=UTF-8'); CWebDavTools::convertToUtf8($response); echo json_encode($response); if ($afterEchoCallback !== null && is_callable($afterEchoCallback)) { call_user_func_array($afterEchoCallback, array()); } require_once $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/main/include/epilog_after.php'; die; }
public function createBlankFile(array $fileData) { $accessToken = $this->getAccessToken(); $googleMimeType = $this->getInternalMimeTypeListByExtension(getFileExtension($fileData['name'])); $fileName = getFileNameWithoutExtension($fileData['name']); CWebDavTools::convertToUtf8($fileName); if (!$googleMimeType) { return false; } $http = new CHTTP(); $http->http_timeout = 10; $arUrl = $http->ParseURL('https://www.googleapis.com/drive/v2/files'); $http->SetAdditionalHeaders(array("Authorization" => "Bearer {$accessToken}")); $postFields = "{\"title\":\"{$fileName}\",\"mimeType\":\"{$googleMimeType}\"}"; $postContentType = 'application/json; charset=UTF-8'; if (!$http->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postFields, $arUrl['proto'], $postContentType)) { return false; } $this->checkHttpResponse($http); // access token expired, let's get a new one and try again if ($http->status == "401") { //todo: invalid credential response return false; } // error checking if ($http->status != "200") { return false; } $finalOutput = json_decode($http->result); //last signed user must delete file from google drive $this->insertPermission(array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id)); return array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id); }