I'm trying to create a website that allows you to upload images to Imgur and stores the url for the image in the database for the site. To that end, I took a lot of code from this Stack overflow post: imgur api won't work , then modified it to fit my code, which is below:
First: my form
<form action="uploadfile.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>
uploadfile.php:
<?
//configuration
define("IMGUR_API_KEY", "");
require("../includes/config.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' => IMGUR_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
{
render("uploadfile_form.php", ["title"=>"Upload Image"]);
}
?>
The configuration and render stuff are just a part of the framework I'm building my site on; just allows my program to run. However when my program does run and it hits line 27, which is this: echo $parser->images->item->links->original;
I get a "Notice: Undefined property: XMLParser::$images in /home/jharvard/vhosts/project/html/uploadfile.php on line 26" and then three more notices for trying to get the property of a non-object on the same line. Any idea what's going wrong with $parser?