Upload the file to imgur using php and get the link

I have an 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 must upload the file to imgur using PHP and get a direct link to this image (this means that the URL must end in .jpg or .png, etc. .)

I would really appreciate if anyone could show me how to upload an image to imgur using PHP and then get a direct link to that image so that I can save the link to the MySQL database. If there is no way to get a direct image link, then a regular imgur link will also work. So 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 was able to upload the image and get json response using api. After I decode json, which returns and var_dump, I get the following:

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) "http://i.imgur.com/yPfV2Tq.png"
  }
  ["success"]=>
  bool(true)
  ["status"]=>
  int(200)
}

Now, how to extract the part by saying http://i.imgur.com/yPfV2Tq.png ?

+4
source share
1 answer

Ok, so I found a way how to do this, Help used here: using imgur api v3 to upload images anonymously using php

Used the code provided by h0tw1r3 in his answer. And used the help of drew010 to extract the link using

$reply->data->link;

, h0tw1r3. xjstratedgebx .

+1

All Articles