Advertisement
kingdomofshawn

Untitled

Sep 15th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?
  2. $img=$_FILES['img'];
  3. if(isset($_POST['submit'])){
  4.  if($img['name']==''){  
  5.   echo "<h2>An Image Please.</h2>";
  6.  }else{
  7.   $filename = $img['tmp_name'];
  8.   $client_id="UNIQUE CLIENT ID GOES HERE";
  9.   $handle = fopen($filename, "r");
  10.   $data = fread($handle, filesize($filename));
  11.   $pvars   = array('image' => base64_encode($data));
  12.   $timeout = 30;
  13.   $curl = curl_init();
  14.   curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
  15.   curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
  16.   curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
  17.   curl_setopt($curl, CURLOPT_POST, 1);
  18.   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  19.   curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
  20.   $out = curl_exec($curl);
  21.   curl_close ($curl);
  22.   $pms = json_decode($out,true);
  23.   $url=$pms['data']['link'];
  24.   if($url!=""){
  25.    echo "<h2>Uploaded Without Any Problem</h2>";
  26.    echo "<img src='$url'/>";
  27.   }else{
  28.    echo "<h2>There's a Problem</h2>";
  29.    echo $pms['data']['error'];  
  30.   }
  31.  }
  32. }
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement