dropbox 폴더의 내용을 표시 가능한 샌드 박스 방식으로 표시하고 (내가 개발 한 웹 사이트에 로그인 한) 탐색 사용자가 폴더 내에서 다양한 파일을 클릭하고 다운로드 할 수 있어야합니다. Dropbox API를 PHP로 구현하는 데 문제가 있습니다
<?php
require_once "bootstrap.php";
if (isset($access_token)) {
header("Location: ./");
exit;
}
try {
// Start a new Dropbox session
$session = new DropboxSession(
$config["dropbox"]["app_key"],
$config["dropbox"]["app_secret"],
$config["dropbox"]["access_type"]
);
// The user is redirected here by Dropbox after the authorization screen
if (!empty($_GET["oauth_token"]) && !empty($_GET["uid"])) {
$uid = $_GET["uid"];
$token = array(
"oauth_token" => $_GET["oauth_token"],
"oauth_token_secret" => ""
);
if (!empty($_SESSION["request_token"])) {
$token["oauth_token_secret"] = $_SESSION["request_token"]["oauth_token_secret"];
}
/**
* The access token is all you'll need for all future API requests on
* behalf of this user, so you should store it away for safe-keeping
* (even though we don't for this article). By storing the access
* token, you won't need to go through the authorization process again
* unless the user revokes access via the Dropbox website.
*/
if ($access_token = $session->obtainAccessToken($token)) {
parse_str($access_token, $token);
$access_token = $token;
unset($token);
// The output ov var_export is similar to:
// array("oauth_token_secret" => "aaaa", "oauth_token" => "bbbb", "uid" => "123456")
$data = '<?php $access_token = ' . var_export($access_token, true) . ";";
if (file_put_contents($config["app"]["authfile"], $data) === false) {
throw new Exception("Unable save access token");
}
// Authorized, redirect to index
//header("Location: index_inside.php");
echo "Authorized, <a href=\"list.php\">click here</a> to redirect!";
exit;
}
// The access token should be stored somewhere to be reused until
// it expires or is revoked by the user
}
else {
// We must start a new authorization cycle
if ($request_token = $session->obtainRequestToken()) {
// The request token must be subdivided in the two components
// oauth_token_secret and oauth_token and kept in the session
// because is needed in the next step
parse_str($request_token, $token);
$_SESSION["request_token"] = $token;
$url = $session->buildAuthorizeURL(
$token,
$config["app"]["root"] . basename($_SERVER["SCRIPT_NAME"]),
"en-US");
// Display or redirect to auth URL
echo '<p>Please visit <a href="' . $url . '">Dropbox</a> and authorize this application.</p>';
exit;
}
else {
throw new Exception("Unable to get request token");
}
}
}
catch (Exception $e) {
echo $e->getMessage();
}
이
은 파일 list_inside입니다 ...<?php
// Prevent calling this script directly
if ($_SERVER["SCRIPT_FILENAME"] == __FILE__) {
exit("Access denied!");
}
// app settings
$config = array();
$config["dropbox"]["app_key"] = "***";
$config["dropbox"]["app_secret"] = "***";
// ACCESS_TYPE should be "dropbox" or "app_folder"
$config["dropbox"]["access_type"] = "dropbox";
$config["app"]["root"] = ((!empty($_SERVER["HTTPS"])) ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . "/";
$config["app"]["datadir"] = dirname(__FILE__) . "/data";
$config["app"]["authfile"] = $config["app"]["datadir"] . "/auth.php";
// turn on error reporting for development
error_reporting(E_ALL|E_STRICT);
ini_set("display_errors", true);
// environment check
if (!is_dir($config["app"]["datadir"]) || !is_writable($config["app"]["datadir"])) {
exit("The data directory is not writeable!");
}
if (file_exists($config["app"]["authfile"]) && !is_writable($config["app"]["authfile"])) {
exit("The auth storage file is not writeable!");
}
// Load libraries and start a new session
require_once "lib/dropbox/rest.php";
require_once "lib/dropbox/session.php";
require_once "lib/dropbox/client.php";
if(!isset($_SESSION)){session_start();}
// Search for a previously obtained access token
$access_token = null;
if (file_exists($config["app"]["authfile"])) {
include_once $config["app"]["authfile"];
}
이
은 파일 authorize.php입니다 ... 이 파일 bootstrap.php입니다 : 여기에 내가 사용하고 코드입니다 (다운로드 링크와 파일을 이상적와) 결국 폴더의 목록을 표시 할 때 포함되는 것 인 ... .PHP 여기<?php
require_once "bootstrap.php";
if (!isset($access_token)) {
header("Location: authorize.php");
exit;
}
try {
// Start a new Dropbox session
// The access token should be defined
// The session should verify if the token is valid and throw an exception
$session = new DropboxSession(
$config["dropbox"]["app_key"],
$config["dropbox"]["app_secret"],
$config["dropbox"]["access_type"],
$access_token
);
$client = new DropboxClient($session);
$path = (!empty($_GET["path"])) ? $_GET["path"] : "/Apps/Tools/";
// List contents of home directory
if ($home = $client->metadata($path)) {
echo "<p>Metadata content for <code>" . $path . "</code></p>";
echo "<pre>" . print_r($home, true) . "</pre>";
}
}
catch (Exception $e) {
echo "<strong>ERROR (" . $e->getCode() . ")</strong>: " . $e->getMessage();
if ($e->getCode() == 401) {
// Remove auth file
unlink($config["app"]["authfile"]);
// Re auth
echo '<p><a href="authorize.php">Click Here to re-authenticate</a></p>';
}
}
는 metada를 사용하여 위의 코드의 출력은 TA()/애플리케이션/툴/어레
메타 콘텐츠 ( [해시] => fa7f3577894553ffeb70ac0d96e49b99 [수요일 수정] => 71,425 [개정판] => 1170104ef29f8 [thumb_exists] => [바이트 ] => 0 [수정] => 2014 년 1 월 14 일 03시 10 분 05 초 +0000 [경로] =>/Apps/Tools [is_dir] => 1 [아이콘] => [루트] => 보관함 [내용] => 배열 ( [0] => 배열 ( ) [수요일 수정] => 71,426 [개정판] => 1170204ef29f8 [thumb_exists] => [바이트] => 0 [변형] => 2014년 1월 14일 (화) 3시 10분 5초 +0000 [경로] =>/앱/도구/사이드 도로 드라이 크릭 밸리 카베르네 소비뇽 [is_dir] => 1 [아이콘] => 폴더 [루트] => 보관 [크기] => 0 바이트 )
[1] => Array ( [revision] => 71436 [rev] => 1170c04ef29f8 [thumb_exists] => [bytes] => 0 [modified] => Tue, 14 Jan 2014 03:10:05 +0000 [path] => /Apps/Tools/Burnside Road Dry Creek Valley Sauvignon Blanc [is_dir] => 1 [icon] => folder [root] => dropbox [size] => 0 bytes ) [2] => Array ( [revision] => 71445 [rev] => 1171504ef29f8 [thumb_exists] => [bytes] => 0 [modified] => Tue, 14 Jan 2014 03:10:05 +0000 [path] => /Apps/Tools/Burnside Road Mendocino County Zinfandel [is_dir] => 1 [icon] => folder [root] => dropbox [size] => 0 bytes ) [3] => Array ( [revision] => 71454 [rev] => 1171e04ef29f8 [thumb_exists] => [bytes] => 0 [modified] => Tue, 14 Jan 2014 03:10:05 +0000 [path] => /Apps/Tools/Burnside Road Pinot Noir California [is_dir] => 1 [icon] => folder [root] => dropbox [size] => 0 bytes ) ) [size] => 0 bytes)
나는 고르지 못한 코드에 대해 사과한다. 그러나 나는이 기술에별로 숙련되어 있지 않다. 그러나 내 친구 ne eds가 사이트를 도와 주었고 dropbox 작동을 돕기 위해 뛰어 들었습니다.
문제는 ... 폴더에 대한 정보 배열을 표시하지만 다운로드 할 링크가있는 파일이 보이지 않습니다.
추가 된 info..here 내가하려고 다른 페이지 코드 :
파일 : 여기
위의 코드에 대한 출력 (내가 직접 PHP를 아래에 이것에 대한 출력 목록) /home/thisisyo/public_html/data/webs.pdf 배열 ( [name] =>/home/thisisyo/public_html/data/webs)에 저장됩니다.PDF [MIME] => 애플리케이션/PDF [메타] => stdClass 개체 ( [수요일 수정] => 35,075 [개정판] => 890304ef29f8 [thumb_exists] => 가 [바이트]>가이 703,289 [변형 =을 ] => 목, 2013 년 6 월 20 일 23시 39 분 10 초 +0000 [client_mtime] => 2013 년 2 월 20 일 수요일 01:19:42 +0000 [경로] => /webs.pdf [is_dir] => [아이콘] => page_white_acrobat [루트] => 보관 [MIME_TYPE] => 애플리케이션/PDF [크기] => 686.8 KB )<?php require_once "bootstrap.php"; if (!isset($access_token)) { header("Location: authorize.php"); exit; } try { // Start a new Dropbox session // The access token should exist // The session should verify if the token is valid and throw an exception $session = new DropboxSession( $config["dropbox"]["app_key"], $config["dropbox"]["app_secret"], $config["dropbox"]["access_type"], $access_token ); $client = new DropboxClient($session); $path = (!empty($_GET["path"])) ? $_GET["path"] : "/webs.pdf"; $dest = $config["app"]["datadir"] . "/" . basename($path); // Download a file if ($file = $client->getFile($path, $dest)) { if (!empty($dest)) { unset($file["data"]); echo "<p>File saved to: <code>" . $dest . "</code></p>"; echo "<pre>" . print_r($file, true) . "</pre>"; } else { header("Content-type: " . $file["mime"]); echo $file["data"]; exit; } } } catch (Exception $e) { echo "<strong>ERROR (" . $e->getCode() . ")</strong>: " . $e->getMessage(); if ($e->getCode() == 401) { // Remove auth file unlink($config["app"]["authfile"]); // Re auth echo '<p><a href="authorize.php">Click Here to re-authenticate</a></p>'; } }
)
는 또한, 여기 client.php에 정의 된 클래스입니다 :
public function metadata($path, $list = true, $fileLimit = 10000, $hash = null, $revision = null, $includeDeleted = false) {
// Prepare argument list
$args = array(
"file_limit" => $fileLimit,
"hash" => $hash,
"list" => (int) $list,
"include_deleted" => (int) $includeDeleted,
"rev" => $revision
);
// Prepend the right access string to the desired path
if ("dropbox" == $this->accessType) {
$path = "dropbox" . $path;
}
else {
$path = "sandbox" . $path;
}
// Execute
$response = $this->Session->fetch("GET", $this->dropboxAPIURL, "/metadata/" . $path, $args);
return $response["body"];
}
이것은 대해서 getFile() 클래스가 정의되어 ...
공공 기능 대해서 getFile ($ 경로, $ OUTFILE = NULL, $ 수요일 수정 = NULL) {
$args = array();
if (!empty($revision)) {
$args["rev"] = $revision;
}
// Prepend the right access string to the desired path
if ("dropbox" == $this->accessType) {
$path = "dropbox" . $path;
}
else {
$path = "sandbox" . $path;
}
// Get the raw response body
$response = $this->Session->fetch("GET", $this->dropboxContentAPIURL, "/files/" . $path, $args, true);
if ($outFile != null) {
if (file_put_contents($outFile, $response["body"]) === false) {
throw new Exception("Unable to write file '$outfile'");
}
}
return array(
"name" => ($outFile) ? $outFile : basename($path),
"mime" => $response["headers"]["content-type"],
"meta" => json_decode($response["headers"]["x-dropbox-metadata"]),
"data" => $response["body"]
);
}
이 코드는, 그 내용의 전체 목록을 작업 뱉어 않는 것을 추가해야 도울 수 있다면 클릭 가능한 링크가있는 멋진 샌드 박스 유형의 출력을 원합니다. – user2990466
예제 출력을 게시 할 수 있습니까? 배열을 반복하는 코드를 작성해야합니다. –
나는 또한 추가 된 코드를 시도하고 코드 출력을 게시 할 것이다. 멀리 주셔서 감사합니다 – user2990466