Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

User talk:Bhavika Jadav

Unable to create a folder in dropbox using Php API Dropbox using Wordpress

Code: // Upload $wpschunks = explode("/",$wpsdbTmpFile); for($i = 0; $i < count($wpschunks); $i++) {

   $c = $i;

} global $current_user; $wpuserid = $current_user->data->ID; $wpusername = $current_user->data->user_login; $newfoldername = $wpusername;

$folderMetadata = $dropbox->getMetaData(trim($wpsdb_path, '/') . '/' . $newfoldername, true);

if (!$folderMetadata['is_dir']) {

   $dropbox->CreateFolder(trim($wpsdb_path, '/') . '/' . $newfoldername, "dropbox");
   if ( !$dropbox->putFile(trim($wpsdb_path,'/').'/'.$newfoldername.'/'.$wpschunks[$c], $wpstmpFile,"dropbox") ) {
       throw new Exception(__('ERROR! Upload Failed.','simpleDbUpload'));
   }
   if($wpsdb_delete_file == "True") {
       if (isset($wpsdbTmpFile) && file_exists($wpsdbTmpFile)) {
           unlink($wpsdbTmpFile);
       }
   }

}



While User uploads the files, the folder should be automatically created in the dropbox with the username as folder name. and then after the files that were uploaded by the user should be saved in that folder. Error thrown: " Error: Resource at uri: https://api.dropbox.com/1/metadata/dropbox/sweety could not be found."

The code is

// Upload $wpschunks = explode("/",$wpsdbTmpFile); for($i = 0; $i < count($wpschunks); $i++) {

   $c = $i;

} global $current_user; $wpuserid = $current_user->data->ID; $wpusername = $current_user->data->user_login; $newfoldername = $wpusername;

// echo trim($wpsdb_path,'/').' //\\ '; $folderMetadata = $dropbox->getMetaData(trim($wpsdb_path, '/') . '/' . $newfoldername, true);

if (!$folderMetadata['is_dir']) {

   $dropbox->CreateFolder(trim($wpsdb_path, '/') . '/' . $newfoldername, "dropbox");
   if ( !$dropbox->putFile(trim($wpsdb_path,'/').'/'.$newfoldername.'/'.$wpschunks[$c], $wpstmpFile,"dropbox") ) {
       throw new Exception(__('ERROR! Upload Failed.','simpleDbUpload'));
   }
   if($wpsdb_delete_file == "True") {
       if (isset($wpsdbTmpFile) && file_exists($wpsdbTmpFile)) {
           unlink($wpsdbTmpFile);
       }
   }

}

Note: When we create the blank folder manually in dropbox and then delete it and then if we try to upload the files the folder is create automatically(using this code) and the files also get uploaded.


Hello! This question is best asked on the support forums, or on WPSE.

Jdgrimes 20:29, 6 December 2013 (UTC)