Example #1
0
 /**
  * @param string $path
  * @return string
  */
 public function getFile($path)
 {
     $stream = fopen('php://temp', 'w+');
     $this->dropbox->getFile('/' . $path, $stream);
     rewind($stream);
     $result = stream_get_contents($stream);
     fclose($stream);
     return $result;
 }
 public function download($hash, $location)
 {
     if (!($remoteLocation = $this->fileExists($hash))) {
         throw new \RuntimeException('File not found!');
     }
     $localFile = fopen($location, 'w+b');
     $metadata = $this->client->getFile($remoteLocation, $localFile);
     fclose($localFile);
     chmod($location, 0664);
     return $metadata;
 }
Example #3
0
 public function readStream($path)
 {
     $stream = fopen('php://temp', 'w+');
     if (!$this->client->getFile($this->prefix($path), $stream)) {
         fclose($stream);
         return false;
     }
     rewind($stream);
     return compact('stream');
 }
 public function downloadFile()
 {
     $input = Input::all();
     $client = new dbx\Client(Session::get("dropbox-token"), $this->_appName);
     $message = "";
     try {
         $metadata = $client->getFile("/" . $input["filename"], fopen($input["filename"], "w"));
         if ($metadata === null) {
             $message = "Could not download file: File doesn't exist!";
         } else {
             $message = "File downloaded! <a href=\"" . $input["filename"] . "\">Click here to download</a> " . json_encode($metadata);
         }
     } catch (Exception $e) {
         $message = "Error on flushing file: " . $e->getMessage();
     }
     // How do I redirect back with data?
     return View::make("dropbox", ["message" => $message]);
 }
Example #5
0
	$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");

	$authCode = trim('4DK3_Q9x-YAAAAAAAAAANH7Nbq9GAa42leQ3914ju_8');

	$authorizeUrl = $webAuth->start();
	echo "1. Go to: " . $authorizeUrl . "<br>";
	echo "2. Click \"Allow\" (you might have to log in first).<br>";
	echo "3. Copy the authorization code and insert it into $authCode.<br>";

	list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
	echo "Access Token: " . $accessToken . "<br>";*/
$accessToken = '4DK3_Q9x-YAAAAAAAAAANZ5B_dVR1tKG78PDXJR4WTWXdCmo0vTSi_enWGrupgSW';
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
/****** Download csv file from dropbox account ***********/
$fa = fopen("data-a.csv", "w+b");
$fileMetadata_a = $dbxClient->getFile("/data-a.csv", $fa);
fclose($fa);
print_r($fileMetadata_a);
$fb = fopen("data-b.csv", "w+b");
$fileMetadata_b = $dbxClient->getFile("/data-b.csv", $fb);
fclose($fb);
print_r($fileMetadata_b);
/****** Get csv data from data-a.csv file ***********/
if (false !== ($ih = fopen('data-a.csv', 'r'))) {
    while (false !== ($data = fgetcsv($ih))) {
        $csvDataA[] = array($data[0], $data[2], $data[4], $data[5]);
    }
}
/****** Get csv data from data-b.csv file ***********/
if (false !== ($ih = fopen('data-b.csv', 'r'))) {
    while (false !== ($data = fgetcsv($ih))) {
 protected function legacy()
 {
     echo "dropbox test";
     /** @var \Shockwavedesign\Mail\Dropbox\Model\Dropbox\User $dropboxUser */
     $dropboxUser = $this->scopeConfig->getDropboxUser();
     $key = $this->config->getValue('system/smtp/dropbox_key', ScopeInterface::SCOPE_STORE);
     $secret = $this->config->getValue('system/smtp/dropbox_secret', ScopeInterface::SCOPE_STORE);
     $accessToken = $dropboxUser->getAccessToken();
     $path = $this->config->getValue('system/smtp/dropbox_host_temp_folder_path', ScopeInterface::SCOPE_STORE);
     $appInfo = dbx\AppInfo::loadFromJson(array('key' => $key, 'secret' => $secret));
     //$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
     //$authorizeUrl = $webAuth->start();
     //echo "1. Go to: " . $authorizeUrl . "\n";
     //echo "2. Click \"Allow\" (you might have to log in first).\n";
     //echo "3. Copy the authorization code.\n";
     //$authCode = "WDUOKE3OsNIAAAAAAAATNEuROlA8b_uXFy0zJ6Rb_XM";
     //list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
     //print "DropboxUserId: " . $dropboxUserId . "Access Token: " . $accessToken . "\n";
     $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     print_r($accountInfo);
     /*
     $f = fopen($path . "test.txt", "rb");
     $result = $dbxClient->uploadFile("/test.txt", dbx\WriteMode::add(), $f);
     fclose($f);
     print_r($result);
     */
     $folderMetadata = $dbxClient->getMetadataWithChildren("/");
     print_r($folderMetadata);
     $f = fopen($path . "test.txt", "w+b");
     $fileMetadata = $dbxClient->getFile("/test.txt", $f);
     fclose($f);
     print_r($fileMetadata);
 }
Example #7
0
 public function store($cloudfile, $path) {
     if (!$this->isAuthorized())
         return CloudDriveResponse::AUTHORIZATION_ERROR;
     try {
         $fout = fopen($path, "w+b");
         $dbxClient = new dbx\Client($this->getAuthorizeToken(), Dropbox::CLIENT);
         $fileMetadata = $dbxClient->getFile($cloudfile->id(), $fout);
         fclose($fout);
         if (is_null($fileMetadata))
             return CloudDriveResponse::FILE_NOT_FOUND;
         return CloudDriveResponse::OK;
     } catch (Exception $ex) {
         return CloudDriveResponse::FILE_NOT_SAVED;
     }
 }
Example #8
0
<?php

# Include the Dropbox SDK libraries
require_once "vendor/dropbox-sdk/Dropbox/autoload.php";
use Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("INSERT_PATH_TO_JSON_CONFIG_PATH");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
$authorizeUrl = $webAuth->start();
echo "1. Go to: " . $authorizeUrl . "\n";
echo "2. Click \"Allow\" (you might have to log in first).\n";
echo "3. Copy the authorization code.\n";
$authCode = \trim(\readline("Enter the authorization code here: "));
list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . "\n";
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$accountInfo = $dbxClient->getAccountInfo();
print_r($accountInfo);
$f = fopen("working-draft.txt", "rb");
$result = $dbxClient->uploadFile("/working-draft.txt", dbx\WriteMode::add(), $f);
fclose($f);
print_r($result);
$folderMetadata = $dbxClient->getMetadataWithChildren("/");
print_r($folderMetadata);
$f = fopen("working-draft.txt", "w+b");
$fileMetadata = $dbxClient->getFile("/working-draft.txt", $f);
fclose($f);
print_r($fileMetadata);
                     $errors .= $error;
                 }
                 $original_bytes = $dropbox_path_file_to_meta[$dropbox_path]['bytes'];
                 if (file_exists($local_path) && $original_bytes == filesize($local_path)) {
                     $count_old_adds++;
                 } else {
                     $count_new_adds++;
                     // if the dir does not exist create it
                     $dirname = dirname($local_path);
                     if (!is_dir($dirname)) {
                         mkdir($dirname, 0755, true);
                     }
                     if ($report_to_screen == 1) {
                         print "getting: {$dropbox_path}\n";
                     }
                     $getfile_metadata = $client->getFile($dropbox_path, fopen($local_path, "w"));
                     if ($getfile_metadata === null) {
                         $error = "file not found on dropbox <dropbox_path>: {$dropbox_path} \n";
                         $errors .= $error;
                     }
                     $msg = "file written to <local_path>: {$local_path} \n";
                     $files_taken .= $local_path . "\n";
                 }
                 // old and new
                 $count_files++;
             }
             // add_file
         }
     }
     // entry
 }
Example #10
0
<?php

require_once "./dropbox-sdk/Dropbox/autoload.php";
use Dropbox as dbx;
$dbxClient = new dbx\Client("uYl-Cut4EBkAAAAAAAAIXwbnQP8Kwr6JrQf8u9iCuh1IRaT8Vk9Yy2V5tK9orBNk", "my-app/1.0");
$f = fopen("./data-b.csv", "a+");
$fileMetadata = $dbxClient->getFile("/data-b.csv", $f);
fclose($f);
print_r($fileMetadata);
Example #11
0
echo "Last reload: " . date('Y-m-d H:i:s');
?>
  <pre><?php 
require_once "../db/db.php";
require_once "../dropbox_token.php";
$db = new TesouroDB("../db/Tesouro.db");
// dropbox
require_once "../dropbox/autoload.php";
use Dropbox as dbx;
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$f = fopen("Tesouro.db", "w+b");
if (flock($f, LOCK_EX)) {
    // acquire an exclusive lock
    ftruncate($f, 0);
    // truncate file
    $fileMetadata = $dbxClient->getFile("/Tesouro.db", $f);
    fflush($f);
    // flush output before releasing the lock
    flock($f, LOCK_UN);
    // release the lock
} else {
    echo "Couldn't get the lock!";
}
fclose($f);
$results = $db->exec("ATTACH '" . getcwd() . "\\Tesouro.db' as toMerge;\n      BEGIN;\n        insert INTO taxa (titulo_id, valor, timestamp) SELECT titulo_id, valor, timestamp from toMerge.taxa;\n      COMMIT;\n      DETACH toMerge;");
require_once "simple_html_dom.php";
$html = file_get_html('http://www.tesouro.fazenda.gov.br/tesouro-direto-precos-e-taxas-dos-titulos');
$results = $db->query('SELECT * FROM "titulo"');
while ($row = $results->fetchArray()) {
    foreach ($html->find('.listing0') as $e1) {
        if (strpos($e1->innertext, $row['nome']) !== false) {
Example #12
0
$second_csv_file = "data-b.csv";
/* Functions End */
/* include Dropbox Library file */
require_once "Dropbox/autoload.php";
use Dropbox as dbx;
//configuration of dropbox
$appInfo = dbx\AppInfo::loadFromJsonFile("app-info.json");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
//access file from dropbox
$accessToken = "4DK3_Q9x-YAAAAAAAAAAS-tnAaiFa42LXEBW2PIWTO4QpfVfMSVtf1kxAhf_WFU3";
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
//list directory of dropbox
$folderMetadata = $dbxClient->getMetadataWithChildren("/");
// Set path to CSV file
$f = fopen($first_csv_file, "w+b");
$csv1_meta = $dbxClient->getFile("/" . $first_csv_file, $f);
fclose($f);
//Set path to CSV file
$f = fopen($second_csv_file, "w+b");
$csv2_meta = $dbxClient->getFile("/" . $second_csv_file, $f);
fclose($f);
$csv1 = readCSV($first_csv_file);
//Set path to CSV file
$csvFile = $second_csv_file;
$csv2 = readCSV($csvFile);
foreach ($csv1 as $s) {
    $array = array();
    $array[] = $s[0];
    $array[] = $s[2];
    $array[] = $s[4];
    $array[] = $s[5];
Example #13
0
?>

<?php 
// Include the Dropbox libraries
require_once "dropbox-sdk/autoload.php";
use Dropbox as dbx;
// Basic configuration
// Setting the app key, secure key and api token
require_once "config/config.php";
$appInfo = dbx\AppInfo::loadFromJsonFile("config/config.json");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
$dbxClient = new dbx\Client(apiToken, "PHP-Example/1.0");
// Reading data-a.csv file
$dataACSV = "data-a.csv";
$dataACSVOpened = fopen($dataACSV, "w+b");
$dbxClient->getFile("/" . $dataACSV, $dataACSVOpened);
fclose($dataACSVOpened);
// Reading data-b.csv file
$dataBCSV = "data-b.csv";
$dataBCSVOpened = fopen($dataBCSV, "w+b");
$dbxClient->getFile("/" . $dataBCSV, $dataBCSVOpened);
fclose($dataBCSVOpened);
// Compairing the csv contents on behalf of relation between the 2nd column of data-a.csv file and 5th column of data-b.csv file.
// Variable: $fileCompareFrom, Consist the data-a.csv file content to compare from data-b.csv content
// Variable: $fileCompareAgainst, Consist the data-b.csv file content to compare against data-a.csv content
$fileCompareFrom = fopen($dataACSV, "r");
$key = 0;
$finalCSVArray = array();
while (!feof($fileCompareFrom)) {
    $array1 = fgetcsv($fileCompareFrom);
    $fileCompareAgainst = fopen($dataBCSV, "r");
<?php

include 'C:\\xampp\\htdocs\\Software_Methodologies_Project\\htdocs\\templates\\parse_csv.php';
date_default_timezone_set("America/Chicago");
require "vendor/autoload.php";
require_once "dropbox-sdk/Dropbox/autoload.php";
use Dropbox as dbx;
$accessToken = "RhUHA_3bYAsAAAAAAAAAKFPP6W9Sv3yhCVVCun37FpkqOYSDvIYPanrtRw1GOFG7";
$dbxClient = new dbx\Client($accessToken, "Software_Methodologies_App");
// This section uploads app.txt to the Dropbox. This is just a test of the upload, it serves no other purpose.
$f = fopen("app.txt", "rb");
$result = $dbxClient->uploadFile("/Software_Methodologies/Input/app.txt", dbx\WriteMode::force(), $f);
fclose($f);
// This section gets actual.csv from the input folder and saves it locally so it can be used elsewhere more easily
$f = fopen("actual.csv", "w+b");
$fileMetadata = $dbxClient->getFile("/Software_Methodologies/Input/actual.csv", $f);
fclose($f);
// This section gets forecasted.csv from the output folder and saves it locally so it can be used elsewhere more easily
$f = fopen("forecast.csv", "w+b");
$fileMetadata = $dbxClient->getFile("/Software_Methodologies/Output/forecasted.csv", $f);
fclose($f);
$app = new \Slim\Slim(array('view' => new \Slim\Views\Twig()));
$app->add(new \Slim\Middleware\SessionCookie());
$view = $app->view();
$view->parserOptions = array('debug' => true);
$view->parserExtensions = array(new \Slim\Views\TwigExtension());
//ADD ALL THE PAGES/////
$app->get('/', function () use($app) {
    $app->render('home.twig');
})->name('home');
$app->get('/w', function () use($app) {
Example #15
0
 } else {
     if ($requestPath == "/download") {
         //$dbxClient = getClient();
         $user = $db->getOne('user');
         $dbxClient = new dbx\Client($user['session'], "PHP-Example/1.0");
         if ($dbxClient === false) {
             header("Location: " . getPath("dropbox-auth-start"));
             exit;
         }
         if (!isset($_GET['path'])) {
             header("Location: " . getPath(""));
             exit;
         }
         $path = $_GET['path'];
         $fd = tmpfile();
         $metadata = $dbxClient->getFile($path, $fd);
         header("Content-Type: {$metadata['mime_type']}");
         fseek($fd, 0);
         fpassthru($fd);
         fclose($fd);
     } else {
         if ($requestPath === "/upload") {
             if (empty($_FILES['file']['name'])) {
                 echo renderHtmlPage("Error", "Please choose a file to upload");
                 exit;
             }
             if (!empty($_FILES['file']['error'])) {
                 echo renderHtmlPage("Error", "Error " . $_FILES['file']['error'] . " uploading file.  See <a href='http://php.net/manual/en/features.file-upload.errors.php'>the docs</a> for details");
                 exit;
             }
             $dbxClient = getClient();