Пример #1
0
 protected function make_request()
 {
     $url = Config::getInstance()->get('api', 'url');
     $link = false;
     foreach ($_FILES as $file) {
         foreach ((array) $file['type'] as $key => $type) {
             if (strpos($type, 'link') !== false) {
                 $link = file_get_contents($file['tmp_name'][$key]);
                 break 2;
             }
         }
     }
     if ($link) {
         if (!Config::getInstance()->get('api', 'inner')) {
             $request = new Request('upload_art', $this, ['file' => $link]);
             $request->perform();
         } else {
             $api = new ApiUploadArt(new ApiRequestInner(['file' => $link]));
             $response = $api->set_base_path(API_IMAGES)->process_request()->get_response();
             $this->recieve_data($response);
         }
         return array();
     }
     // Hacked because of file send
     if (!Config::getInstance()->get('api', 'inner')) {
         $url .= '/upload/art';
         $post = [];
         foreach ($_FILES['file']['tmp_name'] as $key => $file) {
             $post['file' . $key] = '@' . $file . ';filename=' . $_FILES['file']['name'][$key] . ';type=' . $_FILES['file']['type'][$key];
         }
         $header = ['Content-type: multipart/form-data'];
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_ENCODING, '');
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
         $response = curl_exec($ch);
         curl_close($ch);
     } else {
         $api = new ApiUploadArt(new ApiRequest('dummy'));
         $response = $api->set_base_path(API_IMAGES)->process_request()->get_response();
     }
     $this->recieve_data(json_decode($response, true));
     return array();
 }