diff options
author | Simon Rettberg | 2015-09-04 19:03:53 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-09-04 19:03:53 +0200 |
commit | 5435b8d135d2003945e2361d1c82f583570dfdde (patch) | |
tree | ee324f7754e9d9fd1fe4a5b3f3def1e56b8eeb30 /inc/download.inc.php | |
parent | Fix db update by adding missing return statement... (diff) | |
download | slx-admin-5435b8d135d2003945e2361d1c82f583570dfdde.tar.gz slx-admin-5435b8d135d2003945e2361d1c82f583570dfdde.tar.xz slx-admin-5435b8d135d2003945e2361d1c82f583570dfdde.zip |
Many changes
Diffstat (limited to 'inc/download.inc.php')
-rw-r--r-- | inc/download.inc.php | 32 |
1 files changed, 32 insertions, 0 deletions
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 @@ -59,6 +59,38 @@ class Download } /** + * 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. * * @param string $target destination path to download file to |