apps/files_external/3rdparty/Dropbox/API.php
/**
     * Uploads a new file
     *
     * @param string $path Target path (including filename)
     * @param string $file Either a path to a file or a stream resource
     * @param string $root Use this to override the default root path (sandbox/dropbox)
     * @return bool
     */
Uploads a new file

@param string $path Target path (including filename)
@param string $file Either a path to a file or a stream resource
@param string $root Use this to override the default root path (sandbox/dropbox)
@return bool
Uploads a new file @param string $path Target path ( including filename ) @param string $file Either a path to a file or a stream resource @param string $root Use this to override the default root path ( sandbox / dropbox ) @return bool
public function putFile($path, $file, $root = null) {
        if (is_resource($file)) {
            $stat = fstat($file);
            $size = $stat['size'];
        } else if (is_string($file) && is_readable($file)) {
            $size = filesize($file);
        } else {
        	throw new Dropbox_Exception('File must be a file-resource or a file path string');
        }
        if ($this->oauth->isPutSupport()) {
            if ($size) {
                if ($size > $this->chunkSize) {
                    $res = array('uploadID' => null, 'offset' => 0);
                    $i[$res['offset']] = 0;
                    while($i[$res['offset']] < 5) {
                        $res = $this->chunkedUpload($path, $file, $root, true, $res['offset'], $res['uploadID']);
                        if (isset($res['uploadID'])) {
                            if (!isset($i[$res['offset']])) {
                                $i[$res['offset']] = 0;
                            } else {
                                $i[$res['offset']]++;
                            }
                        } else {
                            break;
                        }
                    }
                    return true;
                } else {
                    return $this->putStream($path, $file, $root);
                }
            }
        }
        if ($size > 157286400) {
            throw new Dropbox_Exception("Uploading file to Dropbox failed");
        }
        $directory = dirname($path);
        $filename = basename($path);
        if($directory==='.') $directory = '';
        $directory = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($directory));
        $filename = str_replace('~', '%7E', rawurlencode($filename));
        if (is_null($root)) $root = $this->root;
        if (is_string($file)) {
            $file = fopen($file,'rb');
        } elseif (!is_resource($file)) {
            throw new Dropbox_Exception('File must be a file-resource or a file path string');
        }
       	if (!$this->isSafeMode) {
       		set_time_limit(600);
       	}
        $result=$this->multipartFetch($this->api_content_url . 'files/' .
                $root . '/' . trim($directory,'/'), $file, $filename);
        if(!isset($result["httpStatus"]) || $result["httpStatus"] != 200)
            throw new Dropbox_Exception("Uploading file to Dropbox failed");
        return true;
    }
public function putFile ( $ path , $ file , $ root = null ) { if ( is_resource ( $ file ) ) { $ stat = fstat ( $ file ) ; $ size = $ stat [ 'size' ] ; } else if ( is_string ( $ file ) && is_readable ( $ file ) ) { $ size = filesize ( $ file ) ; } else { throw new Dropbox_Exception ( 'File must be a file-resource or a file path string' ) ; } if ( $ this -> oauth -> isPutSupport ( ) ) { if ( $ size ) { if ( $ size > $ this -> chunkSize ) { $ res = array ( 'uploadID' => null , 'offset' => 0 ) ; $ i [ $ res [ 'offset' ] ] = 0 ; while ( $ i [ $ res [ 'offset' ] ] < 5 ) { $ res = $ this -> chunkedUpload ( $ path , $ file , $ root , true , $ res [ 'offset' ] , $ res [ 'uploadID' ] ) ; if ( isset ( $ res [ 'uploadID' ] ) ) { if ( ! isset ( $ i [ $ res [ 'offset' ] ] ) ) { $ i [ $ res [ 'offset' ] ] = 0 ; } else { $ i [ $ res [ 'offset' ] ] ++ ; } } else { break ; } } return true ; } else { return $ this -> putStream ( $ path , $ file , $ root ) ; } } } if ( $ size > 157286400 ) { throw new Dropbox_Exception ( " Uploading file to Dropbox failed " ) ; } $ directory = dirname ( $ path ) ; $ filename = basename ( $ path ) ; if ( $ directory === '.' ) $ directory = '' ; $ directory = str_replace ( array ( '%2F' , '~' ) , array ( '/' , '%7E' ) , rawurlencode ( $ directory ) ) ; $ filename = str_replace ( '~' , '%7E' , rawurlencode ( $ filename ) ) ; if ( is_null ( $ root ) ) $ root = $ this -> root ; if ( is_string ( $ file ) ) { $ file = fopen ( $ file , 'rb' ) ; } elseif ( ! is_resource ( $ file ) ) { throw new Dropbox_Exception ( 'File must be a file-resource or a file path string' ) ; } if ( ! $ this -> isSafeMode ) { set_time_limit ( 600 ) ; } $ result = $ this -> multipartFetch ( $ this -> api_content_url . 'files/' . $ root . '/' . trim ( $ directory , '/' ) , $ file , $ filename ) ; if ( ! isset ( $ result [ " httpStatus " ] ) || $ result [ " httpStatus " ] != 200 ) throw new Dropbox_Exception ( " Uploading file to Dropbox failed " ) ; return true ; }
Uploads a new file
Uploads a new file
// Dropbox API /files has a maximum file size limit of 150 MB. // https://www.dropbox.com/developers/core/docs#files-POST