Search code examples
dropbox-apidropbox-php

How to create folder(if not exist) in dropbox accout using php-api?


am trying to learn dropbox php-api. i have done upload, but unable to create a new folder(if not exist) in dropbox account

code snippet :

// Create new directory
$create_new_folder = $dropbox->createFolder('new_folder','dropbox');

// Create a temporary file and write some data to it
$tmp = tempnam('/tmp', 'dropbox');
$data = 'This file was uploaded using the Dropbox API!';
file_put_contents($tmp, $data);

// Upload the file with an alternative filename
$put = $dropbox->putFile($tmp, 'abc.txt');

// Unlink the temporary file
unlink($tmp);

// Dump the output
var_dump($put);

error:

Call to undefined method Dropbox\API::createFolder() in C:\wamp\www\BenTheDesigner-Dropbox-b49576c\examples\putFile.php on line 18


Solution

  • This error seems to be indicating that you are trying to call a function named "createFolder" that doesn't exist. Checking the library at:

    https://github.com/BenTheDesigner/Dropbox/blob/master/Dropbox/API.php

    It looks like the function is actually just named "create":

    /**
     * Creates a folder
     * @param string New folder to create relative to root
     * @return object stdClass
     */
    public function create($path)
    {