我有一個關於imgur API的問題。 我想使用imgur api爲我的網站創建一個圖庫,但是如何創建上傳到imgur服務器的文件上傳器?imgur api將無法工作
這裏是我創建:
<?php
include 'xmlparser.php'; // From http://www.criticaldevelopment.net/xml/doc.php
if($_SERVER['REQUEST_METHOD'] == "POST"){
$data = file_get_contents($_FILES["file"]['tmp_name']);
// $data is file data
$pvars = array('image' => base64_encode($data), 'key' => HERE_MY_API_KEY);
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.xml');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$xml = curl_exec($curl);
$parser = new XMLParser($xml);
$parser->Parse();
echo $parser->images->item->links->original;
curl_close ($curl);
}
else
{
?>
<form action="test.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
?>
但這似乎並沒有工作...? 我得到這個錯誤:
解析錯誤:語法錯誤,意想不到的T_STRING,預計在C ')':\ DATA \家\ WWW \ test.php的第7行
和地鐵7是該行:
$pvars = array('image' => base64_encode($data), 'key' => HERE_MY_API_KEY);
什麼問題? imgur api的文檔在這裏: http://api.imgur.com/examples
你們能幫我嗎?
是的,我已經搜查通過這些主題:
HTML Upload Form will only upload files found in the directory of the PHP file
Using jQuery to parse XML returned from PHP script (imgur.com API)
但它並沒有幫助我...
問候
你把引號的API密鑰? – 2011-02-13 19:55:31
@Daniel:不,文檔說我不能那麼做...... – Thew 2011-02-13 19:59:01