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); }
public function closeEditor(Request $request) { $dbxClient = $this->getDropboxClient(); $LocalAddress = $request->input('LocalAddress'); $LocalName = $request->input('LocalName'); $DropBoxFile = $request->input('DropBoxFile'); // $dropboxFileName = $request->input('fileName'); file_put_contents($LocalAddress, $_POST['text']); $editContent = array(); $editContent[0] = htmlspecialchars($_POST['text']); //updated text $editContent[1] = $LocalAddress; // full local folder name with location $editContent[2] = $LocalName; //full local file name $editContent[3] = $DropBoxFile; //full dropbox path with name $LocalName = str_replace(' ', '', $LocalName); $f = fopen($editContent[1], "rb"); $result = $dbxClient->uploadFile($editContent[3], dbx\WriteMode::force(), $f); fclose($f); $dropboxObject = Dropbox::where('userId', Auth::id())->firstOrFail(); $access_token = $dropboxObject->accessToken; $dropboxClient = new dbx\Client($access_token, "PHP-Example/1.0"); $folderMetadata = $dropboxClient->getMetadataWithChildren("/"); $this->deleteFile($LocalAddress); return view('pages.dropbox')->with('dropboxData', $folderMetadata); }
/** * @param string $path * @param string $string */ public function putFile($path, $string) { $stream = fopen('php://temp', 'w+'); fputs($stream, $string); rewind($stream); $this->dropbox->uploadFile('/' . $path, WriteMode::force(), $stream); }
public function __construct(DropboxManager $dropbox, Config $config, Encrypter $crypt) { $this->dropbox = $dropbox; $this->config = $config; $this->crypt = $crypt; $this->writeMode = WriteMode::force(); }
/** * Save file for storage * * @param string $source Source File * @param string $path Remote path * @param bool $override Override * * @return bool * @throws */ public function upload($source, $path, $override = false) { $fd = fopen($source, "rb"); $writeMode = $override === true ? WriteMode::force() : WriteMode::add(); $metadata = $this->dropbox->uploadFile($this->pathRoot . $path, $writeMode, $fd); fclose($fd); return !is_null($metadata); }
/** * @return bool */ public function send() { $sent = true; $files = $this->backup->getFilesTobackup(); foreach ($files as $file => $name) { $file = fopen($file, 'r'); $upload = $this->dropbox->uploadFile($this->folder . '/' . $name, \Dropbox\WriteMode::force(), $file); if (!$upload) { $sent = false; echo 'DROPBOX upload manqu�e de ' . $file . ' vers ' . $this->folder . $name; } } $streams = $this->backup->getStreamsTobackup(); foreach ($streams as $stream => $name) { $upload = $this->dropbox->uploadFileFromString($this->folder . '/' . $name, \Dropbox\WriteMode::force(), $stream); if (!$upload) { $sent = false; echo 'DROPBOX upload manqu�e de ' . $file . ' vers ' . $this->folder . $name; } } return $sent; }
public function write($root, $localfile) { $f = fopen($root . $localfile, "rb"); if (!$f) { throw new Exceptions\FileNotFound("[DROPBOX] File \"{$root}{$localfile}\" not found."); } switch ($this->config["mode"]) { case "rw": $request = dbx\WriteMode::force(); break; case "a": $request = dbx\WriteMode::add(); break; } try { $this->instance->uploadFile($this->config['directory'] . $localfile, $request, $f); } catch (dbx\Exception_NetworkIO $e) { throw new Exceptions\ConnectionReset($e->getMessage()); } catch (dbx\Exception_InvalidAccessToken $e) { throw new Exceptions\RemoteAuthFailed($e->getMessage()); } catch (dbx\Exception_BadRequest $e) { throw new Exceptions\RemoteException("[DROPBOX] Wrong directory or filename."); } }
/** * @param $localFilePath * @param $remoteFilePath * @return array|null * @throws dbx\Exception_BadResponseCode * @throws dbx\Exception_OverQuota * @throws dbx\Exception_RetryLater * @throws dbx\Exception_ServerError */ public function storeLocalFileToRemoteFile($localFilePath, $remoteFilePath) { $handle = fopen($localFilePath, "rb"); $result = $this->getDropboxClient()->uploadFile($remoteFilePath, dbx\WriteMode::force(), $handle); fclose($handle); return $result; }
$password = "******"; // database name to backup $dbName = "cook"; // hostname or IP where database resides $dbHost = "localhost"; // the zip file will have this prefix $prefix = "sql_db_cook_"; // Create the database backup file $sqlFile = $tmpDir . $prefix . date('Y_m_d_h:i:s') . ".sql"; $backupFilename = $prefix . date('Y_m_d_h:i:s') . ".tgz"; $backupFile = $tmpDir . $backupFilename; echo $createBackup = "mysqldump -h " . $dbHost . " -u " . $user . " --password='******' " . $dbName . " --> " . $sqlFile; die; //echo $createBackup; $createZip = "tar cvzf {$backupFile} {$sqlFile}"; //echo $createZip; exec($createBackup); exec($createZip); //now run the DBox app info and set the client; we are naming the app folder SQL_Backup but CHANGE THAT TO YOUR ACTUAL APP FOLDER NAME; $appInfo = dbx\AppInfo::loadFromJsonFile(__DIR__ . "/config.json"); $dbxClient = new dbx\Client($accessToken, "SQL_Backup"); //now the main handling of the zipped file upload; //this message will send in a system e-mail from your cron job (assuming you set up cron to email you); echo "Uploading {$backupFilename} to Dropbox\n"; //this is the actual Dropbox upload method; $f = fopen($backupFile, "rb"); $result = $dbxClient->uploadFile('/SQL_Backup/' . $backupFilename, dbx\WriteMode::force(), $f); fclose($f); // Delete the temporary files // unlink($sqlFile); unlink($backupFile);
protected function processDirectory($dir) { try { $path = $dir['path']; $dirName = substr($path, strrpos($path, '/') + 1); if ($this->processingEtlExists($dirName)) { $this->log($this->processingEtlKey($dirName) . " key exists, directory already processing"); return; } $this->lockProcessingEtl($dirName); $this->log("locked folder with " . $this->processingEtlKey($dirName)); if (!$this->doneExists($dirName)) { $this->log($this->doneEtlKey($dirName) . " not found directory not processable yet, removed key " . $this->processingEtlKey($dirName)); // $this->dropbox->delete($directory . "/.processing_etl"); $this->deleteProcessingEtl($dirName); return; } $this->log("Processing directory {$path}"); $dropboxMetadata = $this->dropbox->getMetadataWithChildren($path); $fileList = $dropboxMetadata['contents']; $this->log('Read data.json'); $dataFile = $this->getDataFile($path); $dataJson = $this->dropboxReadFile($dataFile); $data = json_decode($dataJson, true); $this->log('check authorization'); if (isset($data['payeeId'])) { $token = $data['payeeId']; $authorized = AuthorizationToken::findByToken($token, "User"); } else { $token = isset($data['companyId']) ? $data['companyId'] : $data['publisherId']; $authorized = AuthorizationToken::findByToken($token, "Company"); } if (empty($authorized)) { $this->log("authorization token failed"); $this->deleteProcessingEtl($dirName); return; } if (isset($data['payeeId'])) { $payee = User::find($authorized->model_id); $companyId = $payee->company_id; $payeeCode = $payee->code; } else { $companyId = $authorized->model_id; $payeeCode = null; } $this->log("authorization succeeded"); $publisherAdmins = User::publisherAdmins($companyId); $this->log('check credits'); if (!Company::hasCredits($companyId)) { $this->log("no credits available"); $this->deleteProcessingEtl($dirName); $this->sendEmailToPublisherAdminsNoCredits($publisherAdmins, $companyId); return; } $this->log("company has credits"); if (true || !isset($data['dealId'])) { $this->log('No deal id found, creating deal'); $dealName = isset($data["dealName"]) && !empty($data["dealName"]) ? $data["dealName"] : $dirName; $deal = $this->createDeal($data, $dealName, $companyId, $payeeCode); $data['dealId'] = $deal->id; $this->log("Will upload to {$dataFile}"); $this->dropbox->uploadFileFromString($dataFile, \Dropbox\WriteMode::force(), json_encode($data)); } else { $deal = Deal::find($data['dealId']); } $this->log('Deal id is ' . $deal->id); $statementList = $data['files']; foreach ($statementList as $filename => $metadata) { $this->processFile($filename, $metadata, $fileList, $deal, $path); // break; } $deal->etl_status = 'processed'; $deal->save(); $decremented = Company::decrementCredits($companyId); $this->log("decrement credits " . $decremented); if (count($publisherAdmins)) { $this->sendEmailToPublisherAdmins($publisherAdmins, $deal); $this->log("email sent to publisher"); } else { $this->log("no publisher admins found"); } $moveTo = $this->getDropboxProcessedPath() . '/' . $dirName; $this->dropbox->move($path, $moveTo); $this->log("moved to {$moveTo}"); $this->log("start executing rollups"); RollupEvent::EXECUTE_ROLLUP_TABLES($deal->id); $this->log("end executing rollups"); $this->deleteProcessingEtl($dirName); $this->log("folder unlocked"); } catch (Dropbox\Exception $e) { $this->log('dropbox error: ' . get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); $this->deleteProcessingEtl($dirName); $this->log("folder unlocked"); $this->sendErrorEmailToAdmin($dir, get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); } catch (Exception $e) { $this->log('something bad happened: ' . get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); $this->sendErrorEmailToAdmin($dir, get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); } }
if (strpos($e1->innertext, $row['nome']) !== false) { $taxa = str_replace(",", ".", $e1->parent()->children(2)->innertext()); echo $row['id'] . "\t" . $taxa . "<br>"; $stmt = $db->prepare('INSERT INTO taxa (titulo_id, valor, timestamp) VALUES (:titulo_id, :taxa, :timestamp)'); $stmt->bindValue(':titulo_id', $row['id'], SQLITE3_INTEGER); $stmt->bindValue(':taxa', strval($taxa)); $stmt->bindValue(':timestamp', time()); $stmt->execute(); break; } } } $f = fopen("../db/Tesouro.db", "rb"); if (flock($f, LOCK_EX)) { // acquire an exclusive lock $dbxClient->uploadFile("/Tesouro.db", dbx\WriteMode::force(), $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); $db->close(); unlink("Tesouro.db"); ?> </pre> </body> </html>
// Let user know of success //============================ $errorMsg = "The file " . basename($_FILES['File']['name']) . "has been uploaded"; //============================ // Copy file to dropbox //============================ $dropboxDirectory .= '/LTC-' . $thisYear; $dropboxDirectory .= '/' . trim($church[$SubmitterCong]); $dropboxDirectory .= '/' . trim($participant[$SubmitterID]); $dropboxDirectory = trim($dropboxDirectory); // print "[$dropboxDirectory]<br>[$target_name]<br>\n"; //Login to dropbox $dbxClient = new dbx\Client($accessToken, "LTCSW-Submit"); // Upload the file to dropbox $f = fopen($target_name, "rb"); $result = $dbxClient->uploadFile("{$dropboxDirectory}/" . $_FILES['File']['name'], dbx\WriteMode::force(), $f); fclose($f); //============================ // Send note to IS to process //============================ $toWho = '*****@*****.**'; $toWho .= ',blacksv@juno.com'; $toWho .= ',paul.lemmons@gmail.com'; //$toWho = '*****@*****.**'; $from = 'MIME-Version: 1.0' . "\r\n"; $from .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $from .= "From: LTCSW Seniors Information Upload <*****@*****.**>\r\n"; $subject = "LTC File Uploaded"; $message = "<html><body>\n" . "Hello, This note is to let you know that {$SubmitterName} has " . "uploaded the file:<br /><br />\n" . "<a href=\"http://ltcsw.org/files/" . basename($target_name) . "\">" . $_FILES['File']['name'] . "</a><br /><br />\n" . "You can click on the link above to download this file right now. " . "However, The file can also be found any time on the ltc " . "<a href=\"https://www.dropbox.com/login\">dropbox</a> account." . "Where it will be filed by church and participant for easier " . "reconciliation.<br><br>" . "If you need to contact the submitter they can be reached at: " . "{$SubmitterEmail} <br>" . "<br>" . "Congregation: " . $church[$SubmitterCong] . "<br>" . "Participant: " . $participant[$SubmitterID] . "<br>" . "Event: SeniorsFiles<br>" . "</body></html>\n"; $ret = mail($toWho, $subject, $message, $from); if ($ret == '' or $ret) {
// Specify your sqlite database name and path echo $dbAvail[$fileNum]; echo " - size: "; $fileSize = filesize($dbAvail[$fileNum]); if ($fileSize >= 1073741824) { $fileSize = number_format($fileSize / 1073741824, 2) . ' GB'; } elseif ($fileSize >= 1048576) { $fileSize = number_format($fileSize / 1048576, 1) . ' MB'; } elseif ($fileSize >= 1024) { $fileSize = number_format($fileSize / 1024, 0) . ' KB'; } echo $fileSize; echo "<br />"; } echo "<br />"; for ($fileNum = 0; $fileNum < count($dbAvail); $fileNum++) { // Specify your sqlite database name and path $sourceFile = $dbAvail[$fileNum]; $destinationFile = '/' . substr($dbAvail[$fileNum], 10, 8); $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0"); $accountInfo = $dbxClient->getAccountInfo(); $f = fopen($sourceFile, "rb"); $result = $dbxClient->uploadFile($destinationFile, dbx\WriteMode::force(), $f); fclose($f); echo "<b>Sending result " . substr($dbAvail[$fileNum], 10, 8) . ": </b>"; print_r($result[size]); echo "<br />"; } ?> </body> </html>
# Include the Dropbox SDK libraries require_once ROOT_PATH . "plugins/dropbox-sdk/lib/Dropbox/autoload.php"; include_once ROOT_PATH . 'plugins/mysqldump-php-1.4.1/src/Ifsnop/Mysqldump/Mysqldump.php'; use Dropbox as dbx; try { date_default_timezone_set('Europe/Athens'); // run script only during working hours if (!App::isWorkingDateTimeOn()) { exit; } $filePath = ROOT_PATH . 'storage/excel/'; $curTerms = TermFetcher::retrieveCurrTerm(); foreach ($curTerms as $curTerm) { $curTermId = $curTerm[TermFetcher::DB_COLUMN_ID]; $curTermName = $curTerm[TermFetcher::DB_COLUMN_NAME]; $curTermStartDateTime = new DateTime($curTerm[TermFetcher::DB_COLUMN_START_DATE]); $curTermYear = $curTermStartDateTime->format('Y'); $fullPathFile = Excel::saveAppointments($curTermId); $fileName = pathinfo($fullPathFile)['filename'] . "." . pathinfo($fullPathFile)['extension']; $accessToken = DropboxFetcher::retrieveAccessToken(DropboxCon::SERVICE_APP_EXCEL_BACKUP)[DropboxFetcher::DB_COLUMN_ACCESS_TOKEN]; $dbxClient = new dbx\Client($accessToken, App::getVersion()); $adminAccountInfo = $dbxClient->getAccountInfo(); $f = fopen($fullPathFile, "rb"); $result = $dbxClient->uploadFile("/storage/excel/{$curTermYear}/{$fileName}", dbx\WriteMode::force(), $f); fclose($f); } exit; } catch (\Exception $e) { App::storeError($e); exit; }
/** * Update a file using a stream * * @param string $path * @param resource $resource * @param mixed $config Config object or visibility setting * @return array file metadata */ public function updateStream($path, $resource, $config = null) { return $this->uploadStream($path, $resource, WriteMode::force()); }
} */ // Allow certain file formats // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; ?> <button type = "button" value="Wind Speed" onclick="window.location.href='http://localhost:8000/upload'">Return</button><?php // if everything is ok, try to upload file } if ($uploadOk == 1) { $accessToken = "RhUHA_3bYAsAAAAAAAAAKFPP6W9Sv3yhCVVCun37FpkqOYSDvIYPanrtRw1GOFG7"; $dbxClient = new dbx\Client($accessToken, "Software_Methodologies_App"); ?> <button type = "button" value="Wind Speed" onclick="window.location.href='http://localhost:8000/upload'">Return</button><?php $f = fopen($_FILES["fileToUpload"]["tmp_name"], "rb"); $result = $dbxClient->uploadFile("/Software_Methodologies/Input/actual.csv", dbx\WriteMode::force(), $f); fclose($f); echo "Your file was a csv and was uploaded."; } /* else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; ?><button type = "button" value="Wind Speed" onclick="window.location.href='http://localhost:8000/upload'">Return</button><?php } else { echo "Sorry, there was an error uploading your file."; } }*/
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); } }
public function stream_flush() { switch ($this->file_mode) { case 'r': case 'r+': return false; break; case 'a': case 'a+': $mode = dbx\WriteMode::update(); break; default: $mode = dbx\WriteMode::force(); } fseek($this->temp_file_resource, 0); $this->Client->uploadFileChunked($this->file_path, $mode, $this->temp_file_resource, null, null); return true; }