Пример #1
0
    /**
    * Creates and returns a copy_ref to a file. This reference string can be used to copy that file to another user's Dropbox by passing it in as the from_copy_ref parameter on /fileops/copy.
    *
    * @param type $path
    * @param type $root
    * @return type
    */
    public function copy_ref($path, $root = null) {

    	if (is_null($root)) $root = $this->root;
    	$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
    	$response = $this->oauth->fetch($this->api_url.  'copy_ref/'. $root . '/' . ltrim($path, '/'));
    	return json_decode($response['body'],true);

    }
 /**
  * This method is used to generate multipart POST requests for file upload 
  * 
  * @param string $uri 
  * @param array $arguments 
  * @return bool 
  */
 protected function multipartFetch($uri, $file, $filename)
 {
     /* random string */
     $boundary = 'R50hrfBj5JYyfR3vF3wR96GPCC9Fd2q2pVMERvEaOE3D8LZTgLLbRpNwXek3';
     $headers = array('Content-Type' => 'multipart/form-data; boundary=' . $boundary);
     $body = "--" . $boundary . "\r\n";
     $body .= "Content-Disposition: form-data; name=file; filename=" . $filename . "\r\n";
     $body .= "Content-type: application/octet-stream\r\n";
     $body .= "\r\n";
     $body .= stream_get_contents($file);
     $body .= "\r\n";
     $body .= "--" . $boundary . "--";
     // Dropbox requires the filename to also be part of the regular arguments, so it becomes
     // part of the signature.
     $uri .= '?file=' . $filename;
     return $this->oauth->fetch($uri, $body, 'POST', $headers);
 }