0

ドロップボックス 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