示例#1
0
 public static function post_resource_multipart($uri, $data)
 {
     $auth_uri = Authentication::prepare_authenticated_uri($uri);
     $ch = curl_init($auth_uri);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // do a multipart upload
     $dataarr = Rest::create_multipart($data);
     $headers = $dataarr["headers"];
     $content = $dataarr["content"];
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
     curl_setopt($ch, CURLOPT_HEADER, true);
     $response = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     // return the content location header
     if ($info['http_code'] == 201) {
         $parsed = Rest::parse_http_response($response);
         return array("success" => true, "status-code" => $info['http_code'], "data" => $parsed[0]['content-location']);
     } else {
         return array("success" => false, "status-code" => $info['http_code'], "data" => null);
     }
 }