I have a HTML form with a file upload button. I want the user to be able to select an image and submit the form, then the server should upload the file to imgur using PHP and retrieve the direct link of that image (meaning the URL should end with the .jpg or .png, etc.)
I would really appreciate it if anyone can show me how to upload an image to imgur using PHP and then retrieve the direct link to that image so that I can store the link to a MySQL database. If there is no way to retrieve the direct image link, then the normal imgur link would also work. Meaning something like this will also work:
https://imgur.com/gallery/KlzhGuE
But, the first priority is something like this:
https://i.imgur.com/KlzhGuE.jpg
Edit: So, I managed to upload the image and get a json reply using the api. After I decode the json that is returned back and var_dump it, I get this:
object(stdClass)#1 (3) {
["data"]=>
object(stdClass)#2 (21) {
["id"]=>
string(7) "yPfV2Tq"
["title"]=>
NULL
["description"]=>
NULL
["datetime"]=>
int(1456813618)
["type"]=>
string(9) "image/png"
["animated"]=>
bool(false)
["width"]=>
int(123)
["height"]=>
int(23)
["size"]=>
int(3149)
["views"]=>
int(0)
["bandwidth"]=>
int(0)
["vote"]=>
NULL
["favorite"]=>
bool(false)
["nsfw"]=>
NULL
["section"]=>
NULL
["account_url"]=>
NULL
["account_id"]=>
int(0)
["comment_preview"]=>
NULL
["deletehash"]=>
string(15) "bNjtF9OSdG1QAM7"
["name"]=>
string(0) ""
["link"]=>
string(30) "https://i.sstatic.net/psNPA.png"
}
["success"]=>
bool(true)
["status"]=>
int(200)
}
Now how do it extract the part saying https://i.sstatic.net/psNPA.png ?
Ok so I have found the way how to do it, Used help from here: using imgur api v3 to upload images anonymously using php
Used the code provided by h0tw1r3 in his answer. And used help from drew010 for extracting the link by using
$reply->data->link;
in addition to the code provided by h0tw1r3. Anyways thanks to xjstratedgebx for trying.