/** * @param string $path * @param array|null $extensionFilter * @param bool $includeExtension * @return array Array of filenames * @todo Directories */ public function getFilesList($path, array $extensionFilter = null, $includeExtension = true) { $metadata = $this->dropbox->getMetadataWithChildren('/' . $path); $list = []; foreach ($metadata['contents'] as $file) { $pathParts = pathinfo($file['path']); if (!$extensionFilter or in_array($pathParts['extension'], $extensionFilter)) { if ($includeExtension) { $list[] = trim($file['path'], '/'); } else { $list[] = trim($pathParts['dirname'] . '/' . $pathParts['filename'], '/\\'); } } } return $list; }
public function getFilesFromPath($index, $path, $access_token) { $client = new dbx\Client($access_token, "PHP"); #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) && $data['is_dir'] == 1) { $return_dropfiles = array('type' => 'folder'); $return_dropfiles['content'] = []; $return_dropfiles['service'] = 1; $return_dropfiles['index'] = $index; foreach ($data['contents'] as $file) { $temp = []; $path = $file['path']; //parsing out the filename from the path $namefile = explode('/', $path); $num = count($namefile) - 1; $temp['name'] = $namefile[$num]; $temp['size'] = $file['size']; $temp['kind'] = $file['icon']; $temp['path'] = $path; array_push($return_dropfiles['content'], $temp); } return $return_dropfiles; } else { $link = array('type' => 'file'); $link['service'] = '1'; $link['link'] = $client->createTemporaryDirectLink($data['path']); return $link; } }
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); }
public function dropboxFolder() { try { $dropboxObject = Dropbox::where('userId', Auth::id())->firstOrFail(); $access_token = $dropboxObject->accessToken; $dropboxClient = new dbx\Client($access_token, "PHP-Example/1.0"); $folderMetadata = $dropboxClient->getMetadataWithChildren("/"); return view('pages.dropbox')->with('dropboxData', $folderMetadata); } catch (Exception $exception) { return Response::make('User Not Found' . $exception->getCode()); } }
/** * Get an array of all files in a directory. * * @param string $directory * @return array */ public function files($directory) { $files = array(); $metadata = $this->dropbox->getMetadataWithChildren($this->pathRoot . $directory); if (isset($metadata['contents']) && is_array($metadata['contents'])) { foreach ($metadata['contents'] as $file) { if ($file['is_dir'] == false) { $files[] = $file['path']; } } } return $files; }
public function listContents($directory = '', $recursive = false) { $listing = array(); $directory = trim($directory, '/.'); $location = $this->applyPathPrefix($directory); if (!($result = $this->client->getMetadataWithChildren($location))) { return array(); } foreach ($result['contents'] as $object) { $path = $this->removePathPrefix($object['path']); $listing[] = $this->normalizeObject($object, $path); if ($recursive && $object['is_dir']) { $listing = array_merge($listing, $this->listContents($path, true)); } } return $listing; }
public function retrieveListing($dir, $recursive = true) { $listing = array(); $directory = rtrim($dir, '/.'); $length = strlen($directory) + 1; $location = $this->prefix($directory); if (!($result = $this->client->getMetadataWithChildren($location))) { return array(); } foreach ($result['contents'] as $object) { $listing[] = $this->normalizeObject($object, substr($object['path'], $length)); if ($recursive && $object['is_dir']) { $listing = array_merge($listing, $this->retrieveListing($object['path'])); } } return $listing; }
public function listContents($directory = '', $recursive = false) { $listing = array(); $directory = trim($directory, '/.'); $prefixLength = strlen($this->prefix); $location = '/' . trim($this->prefix($directory), '/'); if (!($result = $this->client->getMetadataWithChildren($location))) { return array(); } foreach ($result['contents'] as $object) { $path = substr($object['path'], $prefixLength); $listing[] = $this->normalizeObject($object, trim($path, '/')); if ($recursive && $object['is_dir']) { $listing = array_merge($listing, $this->listContents($path)); } } return $listing; }
$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); $num = count($namefile) - 1; $actualname = $namefile[$num]; $size = $file['size']; $icon = $file['icon']; $ref_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $email . '&' . $path; print "<tr 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 { #if the file clicked is not a directory (actual file) generate a temp link and download it
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); }
public function getFiles($dir) { $access = $this->getAuthorizeToken(); $files = array(); $dbxClient = new dbx\Client($access, Dropbox::CLIENT); $metadata = $dbxClient->getMetadataWithChildren(strlen($dir) == 0 ? "/" : $dir); $pathsize = strlen($metadata['path']); if ($pathsize > 1) $pathsize++; foreach ($metadata['contents'] as $file) { $path = $file['path']; $files[] = new CloudFile(substr($path, -(strlen($path) - $pathsize)), $file['path'], $file['is_dir'], $file['bytes'], $this->getName()); } return $files; }
<?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);
<?php require __DIR__ . '/vendor/autoload.php'; use Dropbox\Client as DropboxClient; $token = 'KBX87Dt80DcAAAAAAAAAGAsOTb0KrkX1mXvPyoi6k8L1q0cbSnM2oBS-SrUAI19-'; $app = 'Getup.io/1.0'; $dropbox = new DropboxClient($token, $app); var_dump($dropbox->getAccountInfo()); $metadata = $dropbox->getMetadataWithChildren('/consultaleiloes/uploads'); if (isset($metadata['contents']) && is_array($metadata['contents'])) { $contents = $metadata['contents']; $files = array_filter($contents, function ($file) { return $file['is_dir'] != 1; }); $files = array_map(function ($file) { return $file['path']; }, $files); var_dump($files); }
} else { if ($requestPath === "/indexer") { $user = $db->getOne('user'); $dbxClient = new dbx\Client($user['session'], "PHP-Example/1.0"); //$dbxClient = getClient(); if ($dbxClient === false) { header("Location: " . getPath("dropbox-auth-start")); exit; } $db->where('isFolder', 1); $folder = $db->getOne('picture'); if ($folder == null) { header("Location: " . getPath("geocoder")); echo "all done"; } else { $entry = $dbxClient->getMetadataWithChildren($folder['path']); foreach ($entry['contents'] as $child) { $_picture = new DataManager('Picture'); $_picture->setField('idUser', 1); $_picture->setField('path', $child['path']); $_picture->setField('isFolder', $child['is_dir']); if (isset($child['photo_info'])) { if (isset($child['photo_info']['lat_long'])) { $_picture->setField('lat', $child['photo_info']['lat_long'][0]); $_picture->setField('lon', $child['photo_info']['lat_long'][1]); } if (isset($child['photo_info']['time_taken'])) { $when = strtotime($child['photo_info']['time_taken']); $when = date("Y-m-d H:i:s", $when); $_picture->setField('date', $when); }