OSDN Git Service

embr
[embrj/master.git] / lib / image_uploader.php
1 <?php\r
2 \r
3 class image_uploader{\r
4         public $responseInfo;\r
5         public $type = 'xml';\r
6         public $user_agent = 'rabr';\r
7 \r
8         public function imgly($image){\r
9                 $postdata = array( 'media' => "@$image");\r
10                 $request = 'http://img.ly/api/upload';\r
11                 return $this->objectify( $this->process( $request, $postdata ) );\r
12         }\r
13 \r
14         /**** request method ****/\r
15         function process($url,$postargs=false)\r
16         {\r
17                 $ch = curl_init($url);\r
18                 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));\r
19 \r
20                 if($postargs !== false)\r
21                 {\r
22                         curl_setopt ($ch, CURLOPT_POST, true);\r
23                         curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);\r
24                 }\r
25                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r
26                 curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);\r
27                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);\r
28 \r
29                 $response = curl_exec($ch);\r
30 \r
31                 $this->responseInfo=curl_getinfo($ch);\r
32                 curl_close($ch);\r
33                 return $this->responseInfo['http_code'];\r
34                 if( intval( $this->responseInfo['http_code'] ) == 200 )\r
35                         return $response;    \r
36                 else\r
37                         return false;\r
38         }\r
39 \r
40         function objectify( $data )\r
41         {\r
42                 if( function_exists('simplexml_load_string') ) {\r
43                         $obj = simplexml_load_string( $data );\r
44                 }\r
45                 if (isset($obj->error) || !$obj) return false;\r
46                 else return $obj;\r
47         }\r
48 }\r
49 ?>\r