Created
April 14, 2014 00:32
-
-
Save kruxor/10608148 to your computer and use it in GitHub Desktop.
Imgur Upload using v3 api - PHP - JSON : Ignores SSL Cert Errors
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
<html> | |
<body> | |
<form action="upload_img.php" method="post" enctype="multipart/form-data"> | |
<input type="file" name="imgupload" /><br> | |
<input type="submit" value="Upload to Imgur" /> | |
</form> | |
</body> | |
</html> |
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 | |
$error = ""; | |
$client_id = 'Add Client ID Here'; /* http://api.imgur.com/oauth2/addclient */ | |
$file = file_get_contents($_FILES["imgupload"]["tmp_name"]); | |
$url = 'https://api.imgur.com/3/image.json'; | |
$headers = array("Authorization: Client-ID $client_id"); | |
$pvars = array('image' => base64_encode($file)); | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL=> $url, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_POST => 1, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_HTTPHEADER => $headers, | |
CURLOPT_SSL_VERIFYHOST => 0, | |
CURLOPT_SSL_VERIFYPEER => 0, | |
CURLOPT_POSTFIELDS => $pvars | |
)); | |
/* $json_returned = curl_exec($curl); */ // blank response | |
$json_returned = curl_exec($curl); // blank response | |
echo "Result: " . $json_returned ; | |
/* var_dump($json_returned); */ | |
if ($error = curl_error($curl)) { | |
die('cURL error:'.$error); | |
} | |
curl_close ($curl); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment