在php中实现dropbox API的问题

在php中实现dropbox API的问题,php,dropbox,dropbox-api,dropbox-php,Php,Dropbox,Dropbox Api,Dropbox Php,我正在尝试创建一个页面,以一种可呈现的沙盒方式显示dropbox文件夹的内容,并允许登录到我开发的网站的浏览用户能够单击并下载文件夹中的各种文件。 以下是我正在使用的代码: 这是bootstrap.php文件 <?php // Prevent calling this script directly if ($_SERVER["SCRIPT_FILENAME"] == __FILE__) { exit("Access denied!"); } // app setting

我正在尝试创建一个页面,以一种可呈现的沙盒方式显示dropbox文件夹的内容,并允许登录到我开发的网站的浏览用户能够单击并下载文件夹中的各种文件。 以下是我正在使用的代码: 这是bootstrap.php文件

    <?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"];
}
<?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>';
    }
}
; } } 捕获异常$e{ 回显错误。$e->getCode.:。$e->getMessage;
$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"]
);
如果$e->getCode==401{ //删除身份验证文件 取消链接$config[app][authfile]; //重新授权 回响
$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"]
);
} } 以下是使用元数据对上述代码的输出:

<?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>';
    }
}
/Apps/Tools/Array的元数据内容 [哈希]=>fa7f3577894553ffeb70ac0d96e49b99 [修订]=>71425 [rev]=>1171004EF29F8 [拇指_存在]=> [字节]=>0 [修改]=>2014年1月14日星期二03:10:05+0000 [路径]=>/应用程序/工具 [is_dir]=>1 [图标]=>文件夹 [root]=>dropbox [内容]=>数组 [0]=>阵列 [修订]=>71426 [修订]=>1170204ef29f8 [拇指_存在]=> [字节]=>0 [修改]=>2014年1月14日星期二03:10:05+0000 [path]=>/Apps/Tools/Burnside Road Dry Creek Valley赤霞珠 [is_dir]=>1 [图标]=>文件夹 [root]=>dropbox [大小]=>0字节

<?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>';
    }
}
我为代码的混乱道歉,我在这方面不是非常熟练,但是,我的朋友需要网站的帮助,我也加入进来帮助dropbox工作

<?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>';
    }
}
问题是…它显示了有关文件夹的一系列信息,但没有显示带有下载链接的文件

<?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>';
    }
}
添加信息..这里是我尝试的另一个页面代码:我在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 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>';
    }
}
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"];
}
; } 否则{ headerContent类型:.$file[mime]; echo$文件[数据];
$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"]
);
出口 } } } 捕获异常$e{ 回显错误。$e->getCode.:。$e->getMessage;
$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"]
);
如果$e->getCode==401{ //删除身份验证文件 取消链接$config[app][authfile]; //重新授权 回响
$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"]
);
} } 以下是上述代码的输出:

<?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>';
    }
}
文件保存到:/home/thisisyo/public\u html/data/webs.pdf数组 [name]=>/home/thisisyo/public_html/data/webs.pdf [mime]=>应用程序/pdf [meta]=>stdClass对象 [修订]=>35075 [修订]=>890304ef29f8 [拇指_存在]=> [字节]=>703289 [修改]=>2013年6月20日星期四23:39:10+0000 [客户时间]=>2013年2月20日星期三19:19:42+0000 [路径]=>/webs.pdf [is_dir]=> [图标]=>页面\u白色\u acrobat [root]=>dropbox [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>';
    }
}

<?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中定义的类:

<?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>';
    }
}
<?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 <<<EOF
        <h1>Index of $index</h1>

        <table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Last Modified</th>
                    <th>Size</th>
                    <th>Type</th>
                </tr>
            </thead>
            <tbody>
        EOF;

        foreach($home as $list) {
            $link = ($list[is_dir] == 1 ? "list_inside" : "download").".php?path=".$list[path];
            $file = explode("/", $list[path]);
            $path = $file[count($file)-1];
            $size = ($list[bytes] == 0 ? "-" : $list[size]);

            echo <<<EOF
                <tr>
                    <td><a href="$link">$path</a></td>
                    <td>$list[modified]</td>
                    <td>$size</td>
                    <td>$list[type]</td>
                </tr>
            EOF;
        }

        echo <<<EOF
            </tbody>
        </table>
        EOF;
    }
} 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>';
    }
}

?>
这是getFile类定义

<?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>';
    }
}
公共函数getFile$path,$outFile=null,$revision=null{

<?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>';
    }
}
require_once 'dropbox/DropboxClient.php';
$dropbox = new DropboxClient(array(
        'app_key' => DROPBX_API_KEY, 
        'app_secret' => DROPBX_API_SECRET,
        'app_full_access' => TRUE,
),'en');
$fileMetadata = $dropbox->DownloadFile($value->path,'download/'.$file);

}

对于list_inside.php页面,您只需循环遍历$client->元数据数组并打印HTML即可。以下是该页面的示例:

<?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>';
    }
}

您只需要调用一个函数来下载文件

<?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>';
    }
}

如果它能帮助你,请选中此复选框

我应该补充一点,这段代码确实有效,它会从我的dropbox中弹出文件夹Apps/Tools/的完整内容列表,但问题是我想要漂亮的沙盒类型的输出,带有可点击的链接。你能发布一个示例输出吗?您需要编写代码来循环数组。我还尝试了添加的代码,我将发布代码输出yes。谢谢你,顺便问一下,你能否用一个例子来说明你需要如何编写代码来循环数组。
<?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>';
    }
}