public function removeFile($hash)
 {
     if (!($remoteFile = $this->fileExists($hash))) {
         throw new \RuntimeException('File not found!');
     }
     $this->client->delete($remoteFile);
 }
Example #2
0
 public function generate()
 {
     if (PHP_SAPI != 'cli') {
         throw new \Exception("This script only can be used in CLI");
     }
     $config = $this->config->database;
     system('/usr/bin/mysqldump -u ' . $config->username . ' -p' . $config->password . ' -r /tmp/phosphorum.sql ' . $config->dbname);
     system('bzip2 /tmp/phosphorum.sql');
     $sourcePath = '/tmp/phosphorum.sql.bz2';
     if (!file_exists($sourcePath)) {
         throw new \Exception("Backup could not be created");
     }
     list($accessToken, $host) = AuthInfo::loadFromJsonFile(APP_PATH . '/app/config/backup.auth');
     $client = new Client($accessToken, "phosphorum", null, $host);
     $dropboxPath = '/phosphorum.sql.bz2';
     $pathError = Path::findErrorNonRoot($dropboxPath);
     if ($pathError !== null) {
         throw new \Exception("Invalid <dropbox-path>: {$pathError}");
     }
     try {
         $client->delete($dropboxPath);
     } catch (\Exception $e) {
         // ...
     }
     $size = null;
     if (\stream_is_local($sourcePath)) {
         $size = \filesize($sourcePath);
     }
     $fp = fopen($sourcePath, "rb");
     $client->uploadFile($dropboxPath, WriteMode::add(), $fp, $size);
     fclose($fp);
     @unlink($sourcePath);
 }
Example #3
0
 function upload_file_to_dropbox($params = array())
 {
     if (!$params) {
         return;
     }
     if (!($filename = pathinfo($params['source'], PATHINFO_BASENAME))) {
         return;
     }
     /* copy file to Dropbox */
     echo "\naccessing Dropbox...\n";
     if (!($dbxClient = new dbx\Client(@$params['dropbox_access_token'], "PHP-Example/1.0"))) {
         return;
     }
     /* $accountInfo = $dbxClient->getAccountInfo(); print_r($accountInfo); */
     if ($f = Functions::file_open(CONTENT_RESOURCE_LOCAL_PATH . $filename, "rb")) {
         if ($info = $dbxClient->getMetadata($params['dropbox_path'] . $filename)) {
             $dbxClient->delete($params['dropbox_path'] . $filename);
             echo "\nexisting file deleted\n";
         } else {
             echo "\nfile does not exist yet\n";
         }
         if ($info = $dbxClient->uploadFile($params['dropbox_path'] . $filename, dbx\WriteMode::add(), $f)) {
             echo "\nfile uploaded OK\n";
             return true;
         } else {
             echo "\nfile not uploaded!\n";
         }
         fclose($f);
     }
     return false;
 }
 /**
  * Delete Folder
  * 
  * @param string $folder Path folder
  * 
  * @return bool
  * @throws
  */
 public function deleteFolder($folder)
 {
     if (!$this->isDir($folder)) {
         $path = $this->pathRoot . $folder;
         throw new ExceptionStorage("Directory {$path} Not found or Not Is Diretory", static::E_NOT_IS_DIR);
     }
     $metadata = $this->dropbox->delete($this->pathRoot . $folder);
     return !is_null($metadata);
 }
Example #5
0
            $icon = $file['icon'];
            #link each row with it's current path with the file name
            $ref_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $email . '&' . $path;
            print "<tr class=\"filelist\" href=\"{$ref_link}\" style=\"text-align: center\"><td class=\"file\" style=\"text-align: center\">{$email}</td><td class=\"file\" style=\"text-align: center\">{$icon}</td><td class=\"file\" style=\"text-align: center\">{$user}</td><td class=\"file\" style=\"text-align: center\">{$actualname}</td><td class=\"file\" style=\"text-align: center\">{$size}</td><td class=\"file\" style=\"text-align: center\"><a class =\"deletefile\" href=\"{$ref_link}&delete\">Delete</a></td></tr>";
        }
    }
} else {
    #parse the query string
    $peices = explode('&', $_SERVER['QUERY_STRING']);
    $path = $peices[1];
    $path = urldecode($path);
    $account = query("SELECT * FROM dropbox_accounts WHERE (id = ? AND dropbox_email = ?)", $_SESSION["id"], $peices[0]);
    $client = new dbx\Client($account[0]["dropbox_accessToken"], "PHP");
    if (array_key_exists('2', $peices)) {
        if ($peices[2] == 'delete') {
            $client->delete($path);
            $linkback = $_SERVER['HTTP_REFERER'];
            header("Location: {$linkback}");
        }
    } else {
        $email = $account[0]["dropbox_email"];
        $user = $account[0]["dropbox_id"];
        #convert html to plaintext
        #get file information from current path;
        $data = $client->getMetadataWithChildren("{$path}");
        #if the file has 'content' (directory) print out the information like normal
        if (array_key_exists('contents', $data)) {
            foreach ($data['contents'] as $file) {
                $path = $file['path'];
                //parsing out the filename from the path
                $namefile = explode('/', $path);
 public function delete($path)
 {
     return $this->client->delete($this->prefix($path));
 }
Example #7
0
 public function delete($path)
 {
     $location = $this->applyPathPrefix($path);
     return $this->client->delete($location);
 }
 /**
  * {@inheritdoc}
  */
 public function delete($path)
 {
     $location = $this->applyPathPrefix($path);
     $result = $this->client->delete($location);
     return isset($result['is_deleted']) ? $result['is_deleted'] : false;
 }
Example #9
0
<?php

require_once "../vendor/autoload.php";
use Dropbox as dbx;
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
$accessToken = $_SESSION['accessToken'];
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$file = $_POST['file'];
var_dump($file);
$deleteFile = $dbxClient->delete($file);
if ($deleteFile['is_deleted'] == true || ($deleteFile = null)) {
    echo "File deleted successfully<br>";
    echo '<a href="http://localhost:8888/">Back</a>';
} else {
    echo "Deleting failed<br>";
    echo '<a href="http://localhost:8888/>Back</a>';
}