在photobucket上传文件

时间:2011-10-26 15:36:24

标签: php xml photobucket

我想使用Php通过photobucket API上传文件,但出现了时间戳错误。 这是我的代码

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
session_start();
require_once('PBAPI.php');
require_once ('./helper/xmltoarray.php');
require_once ('./helper/curl.php');
require_once('OAuth/Request.php');
require_once('OAuth/Consumer.php');
require_once('OAuth/Signature/hmac_sha1.php');
if ($_FILES["file"]["error"] > 0) {
    echo '<p class="error">Error' . $_FILES["file"]["error"] . '</p>';
    exit;
}
//else {
//
//}
//if ((($_FILES["file"]["type"] == "image/gif")
//        || ($_FILES["file"]["type"] == "image/jpeg")
//        || ($_FILES["file"]["type"] == "image/pjpeg"))
//        && ($_FILES["file"]["size"] < 25000)) {
//    if ($_FILES["file"]["error"] > 0) {
//        echo "Error: " . $_FILES["file"]["error"] . "<br />";
//    }
else {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    if (!move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"])) {

        echo '<p class="error">Some Error is occured in Uploading the file</p>';
        exit;
    }
    try {
        $path = dirname(__FILE__) . '\\upload\\'. $_FILES["file"]["name"];
        echo $path;
        $key = 'xxxxxxxx';
        $sec = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        $api = new PBAPI($key, $sec);
        $api->setOAuthToken($_SESSION['oauth_token'], $_SESSION['oauth_secret']);
        $api->setResponseParser('simplexml');
        $response = $api->album('temp')->upload(array('type' => 'image', 'uploadfile' => '@'.$path, 'title' => 'my upload'))->post();
        var_dump($response);
        // $data = $response['content']['result']['primary']['media'];
    } catch (PBAPI_Exception_Response $e) {
        //echo "RESPONSE $e";
    } catch (PBAPI_Exception $e) {
        //echo "EX $e";
    }
}
?>

响应如下。我不知道为什么会出现这个错误。代码中的一切都很好

<response>
    <status>Exception</status>
    <message>Authentication failed timestamp invalid -1319642824</message>
    <code>7</code>
    <format>xml</format>
    <method>POST</method>
    <timestamp>1319642824</timestamp>
</response>
<!-- den3ws194 @ Wed, 26 Oct 2011 09:27:04 -0600 -->
请任何可以告诉我可能是什么问题的人。

0 个答案:

没有答案