上传照片桶中的文件

发布于 2024-12-12 04:55:50 字数 2624 浏览 1 评论 0原文

我想使用 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 -->

请任何人告诉我可能是什么问题。

I want to upload a file through photobucket API using Php but the timestamp error arises ..
This is my Code

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

the response is given below.i dont know why it is giving this error.Everything is perfectly fine in code

<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 -->

please anyone who can tell me what could be the problem..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文