Example #1
1
 public function upload($article_id)
 {
     $accessToken = Yii::$app->params['accessToken'];
     $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     if ($this->validate()) {
         $image_name = Yii::$app->security->generateRandomString();
         $this->file->saveAs('uploads/' . $image_name . '.' . $this->file->extension);
         $file_name = 'uploads/' . $image_name . '.' . $this->file->extension;
         $f = fopen("{$file_name}", "rb");
         $result = $dbxClient->uploadFile("/{$image_name}" . '.' . $this->file->extension, dbx\WriteMode::add(), $f);
         fclose($f);
         $src = $dbxClient->createShareableLink($result['path']);
         $src[strlen($src) - 1] = '1';
         $image = new Image();
         $image->image_name = $image_name . '.' . $this->file->extension;
         $image->image_article = $article_id;
         $image->image_src_big = $src;
         //small
         $file_name = 'uploads/' . $image_name . '.' . $this->file->extension;
         $resizedFile = 'uploads/small_' . $image_name . '.' . $this->file->extension;
         smart_resize_image($file_name, null, 0, 100, true, $resizedFile, false, false, 100);
         $f = fopen("{$resizedFile}", "rb");
         $result = $dbxClient->uploadFile("/small_" . "{$image_name}" . '.' . $this->file->extension, dbx\WriteMode::add(), $f);
         fclose($f);
         $src = $dbxClient->createShareableLink($result['path']);
         $src[strlen($src) - 1] = '1';
         $image->image_src_small = $src;
         $image->save();
         unlink($file_name);
         unlink($resizedFile);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Get remote url, return false in case of error
  * 
  * @param string $path Remote Path with folder
  * 
  * @return string
  */
 public function getUrl($path)
 {
     $url = '';
     $share = $this->dropbox->createShareableLink($this->pathRoot . $path);
     if ($share) {
         $url = str_replace('www.dropbox.com', 'dl.dropboxusercontent.com', $share);
     }
     return $url;
 }
 /**
  * Upload file to dropbox
  * @param  init $comment_id
  * @param  init $project_id
  * @param  array $commentdata
  * @return void
  */
 function upload_file_dropbox($post_id = 0, $attachment_id)
 {
     require_once MDROP_PATH . '/lib/dropbox/autoload.php';
     $accesstoken = mdrop_get_token(get_current_user_id());
     //'v1FIiYf35K4AAAAAAAADPLhrp-T8miNShTgeuJ5zrDmyb39gf411tgDJx22_ILSK'; //$this->dropbox_accesstoken;
     $dbxClient = new dbx\Client($accesstoken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     $post = get_post($post_id);
     $files = get_attached_file($attachment_id);
     $file_name = basename(get_attached_file($attachment_id));
     $drop_path = '/EmailAttachment/' . $post->post_title . '/' . $file_name;
     $shareableLink = $dbxClient->createShareableLink($drop_path);
     if (!empty($shareableLink)) {
         return;
     }
     $f = fopen($files, "rb");
     $uploaded_file = $dbxClient->uploadFile($drop_path, dbx\WriteMode::add(), $f);
     fclose($f);
     $dropbox_file_path = $uploaded_file['path'];
     $shareableLink = $dbxClient->createShareableLink($drop_path);
     $this->update_dropbox_shareablelink($attachment_id, $shareableLink);
     $this->update_dropbox_filepath($attachment_id, $dropbox_file_path);
 }
Example #4
0
 public function createShareLink(Request $request)
 {
     $filePath = $request->input('hidden-file-path');
     $dropboxObject = Dropbox::where('userId', Auth::id())->firstOrFail();
     $access_token = $dropboxObject->accessToken;
     $dropboxClient = new dbx\Client($access_token, "PHP-Example/1.0");
     $url = $dropboxClient->createShareableLink($filePath);
     $data = array('public_url' => $url, 'userName' => $dropboxObject->username);
     return View("pages.shareLink")->with('publicLink', $data);
     //die();
 }