上传照片桶中的文件
我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论