Beispiel #1
0
 private function handleCurlError(Curl &$curl, $index = false)
 {
     if ($index !== false) {
         $errors = $curl->curlMultiLastError();
         $error = $errors[$index];
     } else {
         $error = $curl->curlLastError();
     }
     if ($error) {
         Flight::json($error->toArray(), 500);
     }
 }
Beispiel #2
0
 public function downloadFile($path, $home = null)
 {
     $url = Config::get('pkg.api_url') . 'pack/download_file' . '?' . http_build_query(compact('path', 'home'));
     $host = Config::get('pkg.api_host');
     $timeout = 0;
     $method = 'GET';
     $options = compact('url', 'host', 'method', 'timeout');
     $options[CURLOPT_HEADER] = 1;
     $curl = new Curl();
     $ret = $curl->curl($options, false, function ($ch, $result) use(&$size) {
         if ($result !== false) {
             $size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
         }
     });
     if ($ret !== false && $ret !== null) {
         $ret = array('header' => substr($ret, 0, $size), 'body' => substr($ret, $size));
     } else {
         $error = $curl->curlLastError();
         $ret = $error->getHttpStatus();
     }
     return $ret;
 }