From 5435b8d135d2003945e2361d1c82f583570dfdde Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 4 Sep 2015 19:03:53 +0200 Subject: Many changes --- inc/download.inc.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'inc/download.inc.php') diff --git a/inc/download.inc.php b/inc/download.inc.php index 6485ee24..5347e2ee 100644 --- a/inc/download.inc.php +++ b/inc/download.inc.php @@ -58,6 +58,38 @@ class Download return $data; } + /** + * POST-Download file, obey given timeout in seconds + * Return data on success, false on failure + * @param string $url URL to fetch + * @param array $params POST params to set in body, list of key-value-pairs + * @param int $timeout timeout in seconds + * @param int $code HTTP response code, or 999 on error + */ + public static function asStringPost($url, $params, $timeout, &$code) + { + $string = ''; + foreach ($params as $k => $v) { + if (!empty($string)) { + $string .= '&'; + } + $string .= $k . '=' . urlencode($v); + } + $ch = self::initCurl($url, $timeout, $head); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $string); + $data = curl_exec($ch); + $head = self::getContents($head); + if (preg_match('#^HTTP/\d+\.\d+ (\d+) #', $head, $out)) { + $code = (int) $out[1]; + } else { + $code = 999; + } + curl_close($ch); + return $data; + } + /** * Download a file from a URL to file. * -- cgit v1.2.3-55-g7522