createFolder() public method

This method returns the information from the newly created directory
public createFolder ( string $path, string $root = null ) : stdclass
$path string
$root string Use this to override the default root path (sandbox/dropbox)
return stdclass
Exemplo n.º 1
0
 public function mkdir($path, $mode, $options)
 {
     $path = $this->initPath($path);
     try {
         self::$dropbox->createFolder($path);
     } catch (Dropbox_Exception $e) {
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 static function DropboxUpload($fileid)
 {
     /*
      * This script shoud upload a file to a 
      * special folder in the users dropbox.
      * The session should bestarted and the
      * user should be logged in already.
      *
      * @author Nils Bussmann <*****@*****.**>
      * @date   05.02.2011
      * @param  filename should be the path to the local file 
      * @param  folder the folder in the dropbox
      *
      * @return  fail:   filename    if something went wrong
      *          success:filename    if everything went right
      *          exists: filename    if the file already exists
      */
     if (isset($fileid)) {
         session_start();
         //generate filename, filepath, intended_path
         //get filename from database
         $db = \DBManager::get();
         $query = "   SELECT dokument_id, range_id, filename, seminar_id\n\t\t\t\t\t\tFROM    dokumente\n\t\t\t\t\t\tWHERE   dokumente.dokument_id =  '{$fileid}' ";
         $file_result = $db->query($query)->fetchAll();
         //get folder from database
         $seminar_id = $file_result[0]["seminar_id"];
         $range_id = $file_result[0]["range_id"];
         $query = "   SELECT  folder.folder_id, folder.name as folder_name, seminare.Seminar_id, seminare.name as seminar_name\n\t\t\t\t\t\tFROM    folder\n\t\t\t\t\t\tJOIN    seminare ON seminare.Seminar_id  =  '{$seminar_id}' \n\t\t\t\t\t\tWHERE   folder.folder_id =  '{$range_id}' ";
         $folder_result = $db->query($query)->fetchAll();
         // repart the important strings
         $filename = \Helper::cleanFilename($file_result[0]["filename"]);
         $file = $GLOBALS['UPLOAD_PATH'] . "/" . substr($fileid, 0, 2) . "/" . $fileid;
         $folder = \Helper::cleanFilename($folder_result[0]["seminar_name"] . "/" . $folder_result[0]["folder_name"]);
         //check if everthing is allright
         if (!isset($filename) || !isset($file) || !isset($folder)) {
             if (!isset($filename)) {
                 $filename = fileid;
             }
             return "fail:" . $filename;
         }
         /* start interaction width dropbox
            session shoud be started, user should logged in
            Please supply your own consumer key and consumer secret */
         $consumerKey = '5wty9mf06gcuco0';
         $consumerSecret = 'hveok3hllw48hji';
         try {
             $oauth = new \Dropbox_OAuth_PEAR($consumerKey, $consumerSecret);
             $dropbox = new \Dropbox_API($oauth, \Dropbox_API::ROOT_SANDBOX);
             $oauth->setToken($_SESSION['oauth_tokens']);
             //Check if the directories are created and
             //single subfolders in $folders
             $folders = explode("/", $folder);
             $checked_path = "/";
             foreach ($folders as $subfolder) {
                 $found_folder = false;
                 $info = $dropbox->getMetaData($checked_path);
                 foreach ($info["contents"] as $meta_info) {
                     if ($meta_info["is_dir"] == 1 && \Helper::endsWith($meta_info["path"], $subfolder)) {
                         $found_folder = true;
                         break;
                     }
                 }
                 if (!$found_folder) {
                     $dropbox->createFolder($checked_path . "/" . $subfolder);
                 }
                 if ($checked_path == "/") {
                     $checked_path .= $subfolder;
                 } else {
                     $checked_path .= "/" . $subfolder;
                 }
             }
             //depending folder exists
             //check if file already exisits
             $found = false;
             // $found shows if file already exisits
             $info = $dropbox->getMetaData($folder);
             foreach ($info["contents"] as $array_files) {
                 if (strpos($array_files["path"], $filename) != false) {
                     $ausgabe = "exists:" . $filename;
                     $found = true;
                 }
             }
             //Upload the file if nessasery
             if ($found == false) {
                 if ($dropbox->putFile($folder . "/" . $filename, $file)) {
                     $ausgabe = "success:" . $filename;
                 } else {
                     $ausgabe = "fail:" . $filename;
                 }
             }
         } catch (Exception $e) {
             // something went wrong, not specified
             // to specify the error there are other exeptions to catch
             $ausgabe = "fail:" . $filename;
         } catch (HTTP_OAuth_Exception $e) {
             $ausgabe = "fail:" . $filename;
         }
     } else {
         $ausgabe = "fail:" . $filename;
     }
     return $ausgabe;
 }