Exemple #1
0
 public function downloadFile(array $fileData)
 {
     $accessToken = $this->getAccessToken();
     $fileId = $fileData['id'];
     $mimeType = $fileData['mimeType'];
     @set_time_limit(0);
     $file = $this->getFile($fileData);
     $http = new HttpClient(array('socketTimeout' => 10, 'version' => HttpClient::HTTP_1_1));
     if (!($file['content'] = $http->get($file['source']))) {
         return false;
     }
     // error checking
     if ($http->getStatus() != "200") {
         return false;
     }
     CWebDavTools::convertFromUtf8($file['name']);
     $this->recoverExtensionInName($file, $mimeType);
     return $file;
 }
 public function downloadFile(array $fileData)
 {
     $accessToken = $this->getAccessToken();
     $id = $fileData['id'];
     $mimeType = $fileData['mimeType'];
     @set_time_limit(0);
     $http = new CHTTP();
     $http->http_timeout = 10;
     $http->SetAdditionalHeaders(array("Authorization" => "Bearer {$accessToken}"));
     if (!$http->GET('https://www.googleapis.com/drive/v2/files/' . $id)) {
         return false;
     }
     // 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;
     }
     $file = json_decode($http->result, true);
     $links = $file['exportLinks'];
     $link = empty($links[$mimeType]) ? '' : $links[$mimeType];
     if (!$link) {
         $link = $file['downloadUrl'];
     }
     $http = new CHTTP();
     $http->http_timeout = 10;
     $http->SetAdditionalHeaders(array("Authorization" => "Bearer {$accessToken}"));
     if (!$http->GET($link)) {
         return false;
     }
     $file['content'] = $http->result ? $http->result : '';
     CWebDavTools::convertFromUtf8($file['title']);
     $file['name'] = $file['title'];
     $this->recoverExtensionInName($file, $mimeType);
     return $file;
 }