i have a question about the imgur api. I want to create a gallery for my website using the imgur api, but how can i create a file uploader that uploads to the imgur servers?
Here is what i created:
<?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->or开发者_如何学运维iginal;
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
}
?>
But this doesn't seem to work...? I get this error:
Parse error: syntax error, unexpected T_STRING, expecting ')' in C:\data\home\www\test.php on line 7
And line 7 is this row:
$pvars = array('image' => base64_encode($data), 'key' => HERE_MY_API_KEY);
What is wrong? The documentation of the imgur api is here: http://api.imgur.com/examples
Can you guys help me?
And yes, i already searched through these topics:
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)But it didn't help me...
Greetings
Put the API key in quote marks. The way they put it in all caps and outside quote marks is to signify a constant value.
Make sure you register for anonymous API and not Authenticated API here http://imgur.com/register/api
Pulled my hair off for this
精彩评论