0

我正在尝试从 Dropbox sdk 中获取一个示例来工作。

这是根目录中 index.php 中的一些代码。

    $req = $_SERVER['SCRIPT_NAME'];

    if ($req === "/") {
 //a bunch of code and elseif:s
}else{
    echo renderHtmlPage("Bad URL", "No handler for $req");
    exit;
}

我得到以下输出:

Bad URL

No handler for /index.php

为什么 req 设置为 index 以及它如何设置为 / 例如?

完整代码

   $dbxClient = getClient();

    if ($dbxClient === false) {
        header("Location: /dropbox-auth-start");
        exit;
    }

    $path = "/";
    if (isset($_GET['path'])) $path = $_GET['path'];

    if (isset($_GET['dl'])) {
        passFileToBrowser($dbxClient, $path);
    }
    else {
        $entry = $dbxClient->getMetadataWithChildren($path);

        if ($entry['is_dir']) {
            echo renderFolder($entry);
        }
        else {
            echo renderFile($entry);
        }
    }
}
else if ($req === "/dropbox-auth-start") {
    $authorizeUrl = getWebAuth()->start();
    header("Location: $authorizeUrl");
}
else if ($req === "/dropbox-auth-finish") {
    try {
        list($accessToken, $userId, $urlState) = getWebAuth()->finish($_GET);
        assert($urlState === null);
        unset($_SESSION['dropbox-auth-csrf-token']);
    }
    catch (dbx\WebAuthException_BadRequest $ex) {
        error_log("/dropbox-auth-finish: bad request: " . $ex->getMessage());
        // Respond with an HTTP 400 and display error page...
        exit;
    }
    catch (dbx\WebAuthException_BadState $ex) {
        // Auth session expired.  Restart the auth process.
        header('Location: /dropbox-auth-start');
        exit;
    }
    catch (dbx\WebAuthException_Csrf $ex) {
        error_log("/dropbox-auth-finish: CSRF mismatch: " . $ex->getMessage());
        // Respond with HTTP 403 and display error page...
        exit;
    }
    catch (dbx\WebAuthException_NotApproved $ex) {
        echo renderHtmlPage("Not Authorized?", "Why not, bro?");
        exit;
    }
    catch (dbx\WebAuthException_Provider $ex) {
        error_log("/dropbox-auth-finish: unknown error: " . $ex->getMessage());
        exit;
    }
    catch (dbx\Exception $ex) {
        error_log("/dropbox-auth-finish: error communicating with Dropbox API: " . $ex->getMessage());
        exit;
    }

    // NOTE: A real web app would store the access token in a database.
    $_SESSION['access-token'] = $accessToken;

    echo renderHtmlPage("Authorized!", "Auth complete, <a href='/'>click here</a> to browse");
}
else if ($req === "/unlink") {
    // "Forget" the access token.
    unset($_SESSION['access-token']);
    header("Location: /");
}
else if ($req === "/upload") {
    if (empty($_FILES['file']['name'])) {
        echo renderHtmlPage("Error", "Please choose a file to upload");
        exit;
    }

    if (!empty($_FILES['file']['error'])) {
        echo renderHtmlPage("Error", "Error ".$_FILES['file']['error']." uploading file.  See <a href='http://php.net/manual/en/features.file-upload.errors.php'>the docs</a> for details");
        exit;
    }

    $dbxClient = getClient();

    $remoteDir = "/";
    if (isset($_POST['folder'])) $remoteDir = $_POST['folder'];

    $remotePath = rtrim($remoteDir, "/")."/".$_FILES['file']['name'];

    $fp = fopen($_FILES['file']['tmp_name'], "rb");
    $result = $dbxClient->uploadFile($remotePath, dbx\WriteMode::add(), $fp);
    fclose($fp);
    $str = print_r($result, TRUE);
    echo renderHtmlPage("Uploading File", "Result: <pre>$str</pre>");
}
4

0 回答 0