apps/files_external/3rdparty/Dropbox/API.php
/**
     * Uploads large files to Dropbox in mulitple chunks
     * 
     * @param string $file Absolute path to the file to be uploaded
     * @param string|bool $filename The destination filename of the uploaded file
     * @param string $path Path to upload the file to, relative to root
     * @param boolean $overwrite Should the file be overwritten? (Default: true)
     * @return stdClass
     */
Uploads large files to Dropbox in mulitple chunks

@param string $file Absolute path to the file to be uploaded
@param string|bool $filename The destination filename of the uploaded file
@param string $path Path to upload the file to, relative to root
@param boolean $overwrite Should the file be overwritten. (Default: true)
@return stdClass
Uploads large files to Dropbox in mulitple chunks @param string $file Absolute path to the file to be uploaded @param string|bool $filename The destination filename of the uploaded file @param string $path Path to upload the file to relative to root @param boolean $overwrite Should the file be overwritten . ( Default : true ) @return stdClass
public function chunkedUpload($path, $handle, $root = null, $overwrite = true, $offset = 0, $uploadID = null)
    {
        if (is_string($handle) && is_readable($handle)) {
            $handle = fopen($handle, 'rb');
        }
        if (is_resource($handle)) {
            fseek($handle, $offset);
            while ($data = fread($handle, $this->chunkSize)) {
                if (!$this->isSafeMode) {
                	set_time_limit(600);
                }
                $chunkHandle = fopen('php://temp', 'rwb');
                fwrite($chunkHandle, $data);
                $this->oauth->setInFile($chunkHandle);
                $params = array('upload_id' => $uploadID, 'offset' => $offset);
                try {
                    $res = $this->oauth->fetch($this->api_content_url . 'chunked_upload', $params, 'PUT');
                    $response = json_decode($res['body'], true);
                } catch (Exception $e) {
                    $res = $this->oauth->getLastResponse();
                    if ($response['httpStatus'] == 400) {
                        $response = json_decode($res['body'], true);
                        $uploadID = $response['upload_id'];
                        $offset = $response['offset'];
                        return array('uploadID' => $uploadID, 'offset' => $offset);
                    } else {
                        throw $e;
                    }
                    throw $e;
                }
                if (isset($response['upload_id'])) {
                    $uploadID = $response['upload_id'];
                }
                if (isset($response['offset'])) {
                    $offset = $response['offset'];
                }
                fclose($chunkHandle);
            }
            $path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
            if (is_null($root)) {
            	$root = $this->root;
            }
            $params = array('overwrite' => (int) $overwrite, 'upload_id' => $uploadID);
            return $this->oauth->fetch($this->api_content_url . 'commit_chunked_upload/' .
                    $root . '/' . ltrim($path,'/'), $params, 'POST');
        } else {
            throw new Dropbox_Exception('Could not open ' . $handle . ' for reading');
        }
    }
public function chunkedUpload ( $ path , $ handle , $ root = null , $ overwrite = true , $ offset = 0 , $ uploadID = null ) { if ( is_string ( $ handle ) && is_readable ( $ handle ) ) { $ handle = fopen ( $ handle , 'rb' ) ; } if ( is_resource ( $ handle ) ) { fseek ( $ handle , $ offset ) ; while ( $ data = fread ( $ handle , $ this -> chunkSize ) ) { if ( ! $ this -> isSafeMode ) { set_time_limit ( 600 ) ; } $ chunkHandle = fopen ( 'php://temp' , 'rwb' ) ; fwrite ( $ chunkHandle , $ data ) ; $ this -> oauth -> setInFile ( $ chunkHandle ) ; $ params = array ( 'upload_id' => $ uploadID , 'offset' => $ offset ) ; try { $ res = $ this -> oauth -> fetch ( $ this -> api_content_url . 'chunked_upload' , $ params , 'PUT' ) ; $ response = json_decode ( $ res [ 'body' ] , true ) ; } catch ( Exception $ e ) { $ res = $ this -> oauth -> getLastResponse ( ) ; if ( $ response [ 'httpStatus' ] == 400 ) { $ response = json_decode ( $ res [ 'body' ] , true ) ; $ uploadID = $ response [ 'upload_id' ] ; $ offset = $ response [ 'offset' ] ; return array ( 'uploadID' => $ uploadID , 'offset' => $ offset ) ; } else { throw $ e ; } throw $ e ; } if ( isset ( $ response [ 'upload_id' ] ) ) { $ uploadID = $ response [ 'upload_id' ] ; } if ( isset ( $ response [ 'offset' ] ) ) { $ offset = $ response [ 'offset' ] ; } fclose ( $ chunkHandle ) ; } $ path = str_replace ( array ( '%2F' , '~' ) , array ( '/' , '%7E' ) , rawurlencode ( $ path ) ) ; if ( is_null ( $ root ) ) { $ root = $ this -> root ; } $ params = array ( 'overwrite' => ( int ) $ overwrite , 'upload_id' => $ uploadID ) ; return $ this -> oauth -> fetch ( $ this -> api_content_url . 'commit_chunked_upload/' . $ root . '/' . ltrim ( $ path , '/' ) , $ params , 'POST' ) ; } else { throw new Dropbox_Exception ( 'Could not open ' . $ handle . ' for reading' ) ; } }
Uploads large files to Dropbox in mulitple chunks
Uploads large files to Dropbox in mulitple chunks
// Seek to the correct position on the file pointer // Read from the file handle until EOF, uploading each chunk // Open a temporary file handle and write a chunk of data to it // Set the file, request parameters and send the request // Attempt to upload the current chunk // Incorrect offset supplied, return expected offset and upload ID // Re-throw the caught Exception // On subsequent chunks, use the upload ID returned by the previous request // Set the data offset // Close the file handle for this chunk // Complete the chunked upload