Created
December 23, 2013 08:41
-
-
Save karmiphuc/8093576 to your computer and use it in GitHub Desktop.
Upload an Image from a URL to Imgur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Original script source http://designshack.net/articles/javascript/how-to-build-a-dynamic-imgur-upload-app-using-jquery-php/ | |
* | |
* http://playground.zaplabs.com/sandbox/qa/stackexchange/stackoverflow/17269448/index.php | |
* http://playground.zaplabs.com/sandbox/qa/stackexchange/stackoverflow/17269448/index.php.source | |
*/ | |
function uploadToImgur($image) { | |
$client_id = "IMGUR_CLIENT_ID"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json'); | |
curl_setopt($ch, CURLOPT_POST, TRUE); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Client-ID ' . $client_id )); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'image' => $image, 'type' => 'url' )); | |
$reply = curl_exec($ch); | |
curl_close($ch); | |
$reply = json_decode($reply); | |
return strval($reply->data->link); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment