Beispiel #1
0
 /**
  * Downloads a file
  * Returns the base filename, raw file data and mime type returned by Fileinfo
  * @param string $file Path to file, relative to root, including path
  * @param string $outFile Filename to write the downloaded file to
  * @param string $revision The revision of the file to retrieve
  * @return array
  */
 public function getFile($file, $outFile = false, $revision = null)
 {
     // Only allow php response format for this call
     if ($this->responseFormat !== 'php') {
         throw new Exception('This method only supports the `php` response format');
     }
     $handle = null;
     if ($outFile !== false) {
         // Create a file handle if $outFile is specified
         if (!($handle = fopen($outFile, 'w'))) {
             throw new Exception("Unable to open file handle for {$outFile}");
         } else {
             $this->OAuth->setOutFile($handle);
         }
     }
     $file = $this->encodePath($file);
     $call = 'files/' . $this->root . '/' . $file;
     $params = array('rev' => $revision);
     $response = $this->fetch('GET', self::CONTENT_URL, $call, $params);
     // Close the file handle if one was opened
     if ($handle) {
         fclose($handle);
     }
     return array('name' => $outFile ? $outFile : basename($file), 'mime' => $this->getMimeType($outFile ?: $response['body'], $outFile), 'meta' => json_decode($response['headers']['x-dropbox-metadata']), 'data' => $response['body']);
 }
 /**
  * Downloads a file
  * Returns the base filename, raw file data and mime type returned by Fileinfo
  * @param string $file Path to file, relative to root, including path
  * @param string $outFile Filename to write the downloaded file to
  * @param string $revision The revision of the file to retrieve
  * @param boolean $allow_resume - append to the file if it already exists
  * @return array
  */
 public function getFile($file, $outFile = false, $revision = null, $allow_resume = false)
 {
     // Only allow php response format for this call
     if ($this->responseFormat !== 'php') {
         throw new Exception('This method only supports the `php` response format');
     }
     $handle = null;
     if ($outFile !== false) {
         // Create a file handle if $outFile is specified
         if ($allow_resume && file_exists($outFile)) {
             if (!($handle = fopen($outFile, 'a'))) {
                 throw new Exception("Unable to open file handle for {$outFile}");
             } else {
                 $this->OAuth->setOutFile($handle);
                 $params['headers'] = array('Range: bytes=' . filesize($outFile) . '-');
             }
         } elseif (!($handle = fopen($outFile, 'w'))) {
             throw new Exception("Unable to open file handle for {$outFile}");
         } else {
             $this->OAuth->setOutFile($handle);
         }
     }
     $file = $this->encodePath($file);
     $call = 'files/download';
     $params = array('path' => '/' . $file, 'api_v2' => true, 'content_download' => true);
     $response = $this->fetch('POST', self::CONTENT_URL_V2, $call, $params);
     // Close the file handle if one was opened
     if ($handle) {
         fclose($handle);
     }
     return array('name' => $outFile ? $outFile : basename($file), 'mime' => $this->getMimeType($outFile ? $outFile : $response['body'], $outFile), 'meta' => json_decode($response['headers']['dropbox-api-result']), 'data' => $response['body']);
 }