Permalink
Browse files

now uploading files to img.ur instead of s3

  • Loading branch information...
1 parent ccdad59 commit 68819b7a60cd5aebc8cda4b399f47529614c13bc @rkononov committed Mar 6, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 workers/lib/Imgur.php
View
@@ -0,0 +1,20 @@
+<?
+ function upload_file($file_name)
+ {
+ $handle = fopen($file_name, "r");
+ $data = fread($handle, filesize($file_name));
+ $pvars = array('image' => base64_encode($data), 'key' => "b3625162d3418ac51a9ee805b1840452");
+ $timeout = 30;
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.xml');
+ curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
+ curl_setopt($curl, CURLOPT_POST, 1);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
+ $xml = curl_exec($curl);
+ curl_close ($curl);
+ $element_name = "original";
+ preg_match('#<'.$element_name.'(?:\s+[^>]+)?>(.*?)</'.$element_name.'>#s', $xml, $matches);
+ return $matches[1];
+ }
+?>

0 comments on commit 68819b7

Please sign in to comment.