Example #1
0
 public function upload($file)
 {
     $authStuff = json_decode(file_get_contents($this->getAuthFilePath()));
     $dbxClient = new \Dropbox\Client($authStuff->token, "PHP-Example/1.0");
     $f = fopen($file, "rb");
     $dbxClient->uploadFile('/' . basename($file), \Dropbox\WriteMode::force(), $f);
 }
Example #2
0
 /**
  * @param string $localPath
  * @param string $filename
  *
  * @return string URL
  */
 public function upload($localPath, $filename)
 {
     $size = @getimagesize($localPath);
     if ($size) {
         $extension = image_type_to_extension($size[2]);
     } else {
         $extension = strrchr($filename, '.');
     }
     $metadata = $this->client->uploadFile($this->prefix . hash_file('crc32b', $localPath) . $extension, Dropbox\WriteMode::add(), fopen($localPath, 'rb'), filesize($localPath));
     if (is_array($metadata) && isset($metadata['path'])) {
         //return $this->client->createShareableLink($metadata['path']);
         $data = $this->client->createTemporaryDirectLink($metadata['path']);
         if (is_array($data)) {
             return $data[0];
         }
     }
     return null;
 }
Example #3
0
 public function upload_revision()
 {
     $this->is_vendor();
     if (isset($_POST['event_id']) && isset($_POST['photo_name']) && isset($_FILES["file"])) {
         $this->load->model('layout_comment_model', 'layout_comment');
         $fd = fopen($_FILES["file"]['tmp_name'], "rb");
         $dbxClient = new \Dropbox\Client(getenv('DROPBOX_ACCESS_TOKEN'), "chaar-bhai/1.0");
         $dbxClient->uploadFile('/' . $_POST['client_username'] . '/' . rawurldecode($_POST['project_name']) . '/' . rawurldecode($_POST['event_name']) . '/layouts/' . $_POST['photo_name'], \Dropbox\WriteMode::force(), $fd);
         fclose($fd);
         $this->layout_comment->update_by('event_id = ' . $_POST['event_id'] . ' AND title = "' . pathinfo($_POST['photo_name'], PATHINFO_FILENAME) . '"', array('reworked' => '1'));
         redirect(isset($_POST['layout']) ? 'albums/rework/' . $_POST['project_name'] . '/' . $_POST['event_name'] . '/' . $_POST['layout'] : 'albums/rework/' . $_POST['project_name'] . '/' . $_POST['event_name']);
     } else {
         $this->response(array('error' => 'Bad request'), 400);
     }
 }
Example #4
0
 /**
  * Upload files to dropbox
  *
  * @since  1.0
  * @uses   \Dropbox\Client
  * @see    https://www.dropbox.com/developers/core/start/php#uploading
  * @param  array $files
  * @param bool $offline
  * @return integer
  */
 public function upload($files = array(), $offline = false)
 {
     if ($this->isAuthenticated() === false) {
         return 401;
     }
     if (empty($files)) {
         return 404;
     }
     $filepath = $this->getBackupsPath();
     /*if (null === $token = $this->readToken()) {
           $token = $_SESSION[self::TOKEN_SESS_NAME];
       }*/
     $token = $this->getToken();
     $client = new Dropbox\Client($token, $this->applicationName);
     foreach ($files as $file) {
         $file = basename($file);
         if (file_exists($filepath . $file)) {
             try {
                 $stream = @fopen($filepath . $file, 'rb');
                 $client->uploadFile($this->getDropboxPath() . $file, Dropbox\WriteMode::add(), $stream);
                 fclose($stream);
             } catch (Exception $ex) {
                 $this->pushError($ex->getMessage());
                 return 500;
             }
         }
     }
     return 200;
 }
Example #5
0
 /**
  * Send the request to the Dropbox service
  *
  * @param $url string       	
  * @param $post boolean       	
  * @param $postData array       	
  * @throws Exception
  * @return mixed
  */
 protected static function request($url, $post = false, $postData = array())
 {
     try {
         $token = Settings::findbyParam('dropbox_token');
         $dropbox = new Dropbox\Client($token, 'shineisp', null, self::$appInfo->getHost());
         $fh = fopen($postData['file'], "rb");
         $result = $dropbox->uploadFile($postData['dest'] . basename($postData['file']), Dropbox\WriteMode::force(), $fh);
         fclose($fh);
         return $result;
     } catch (Exception $e) {
         Shineisp_Commons_Utilities::log(__METHOD__ . " " . $e->getMessage(), "plugin_dropbox.log");
     }
 }
Example #6
0
function load_image($image)
{
    ini_set('display_errors', 1);
    $size = $_FILES[image_to_load][size][0];
    $type = pathinfo($image, PATHINFO_EXTENSION);
    $date = date("Y-m-d");
    $mail = $_SESSION["user"];
    $connect = mysql_connect("localhost", "root", "123");
    mysql_select_db("POKS");
    $query_relult = mysql_query("select userId from User where email = '{$mail}'") or die("Не удалось провести запрос к базе данных function load_image");
    $id_user = mysql_fetch_array($query_relult);
    $id_user = $id_user[0];
    // 		echo "<br>";
    // 		print($image);
    // 		echo "<br>";
    // 		print($type);
    // 		echo "<br>";
    // 		print($size);
    // 		echo "<br>";
    // 		print($date);
    // 		echo "<br>";
    // 		print($mail);
    // 		echo "<br>";
    // 		print("ID: ".$id_user);
    // 		echo "<br>";
    mysql_query("insert into `userStorrage`(`idUser`,`dateOfCreation`,`size`,`format`,`namePicture`) values('{$id_user}','{$date}','{$size}','{$type}','{$image}')") or die("Не удалось провести запрос к базе данных function load_image insert");
    mysql_close($connect);
    //
    print '<pre>';
    # Include the Dropbox SDK libraries
    require_once './dropbox-sdk-php-1.1.5/lib/Dropbox/autoload.php';
    //MODX_BASE_PATH.
    //use \Dropbox as dbx;
    $accessToken = "-QAlimGqvKAAAAAAAAAAjRWBUFnqWI0AuJV06CSJtnvDKFYMpujYYU2h4fN7-Hlv";
    // Здесь ваш Access token
    $Folder_name = "ITMO_POKS_FOLDER";
    $dbxClient = new \Dropbox\Client($accessToken, $Folder_name);
    print_r($_FILES);
    $dir = "Loads/";
    if (is_uploaded_file($_FILES["image_to_load"]["tmp_name"][0])) {
        $res = move_uploaded_file($_FILES["image_to_load"]["tmp_name"][0], $dir . $_FILES["image_to_load"]["name"][0]);
        if ($res) {
            echo "Succesfully uploaded in " . $dir . $_FILES["image_to_load"]["name"][0];
        } else {
            echo "ERROR";
        }
    }
    /*
     		$tmp_name = $_FILES["image_to_load"]["tmp_name"][0];
            $name = $_FILES["image_to_load"]["name"][0];
            move_uploaded_file($tmp_name, "./Loads/".$name);*/
    chmod($dir . $_FILES["image_to_load"]["name"][0], 0777);
    $fd = fopen($dir . $_FILES["image_to_load"]["name"][0], "r");
    $md1 = $dbxClient->uploadFile("/" . $_SESSION["user"] . "/" . $_FILES[image_to_load][name][0], \Dropbox\WriteMode::add(), $fd);
    fclose($fd);
    print "db answer: ";
    print_r($md1);
    return TRUE;
}