BookStack/app/Uploads/HttpFetcher.php

38 lines
713 B
PHP
Raw Normal View History

2021-06-26 15:23:15 +00:00
<?php
namespace BookStack\Uploads;
use BookStack\Exceptions\HttpFetchException;
class HttpFetcher
{
/**
* Fetch content from an external URI.
2021-06-26 15:23:15 +00:00
*
* @param string $uri
2021-06-26 15:23:15 +00:00
*
* @throws HttpFetchException
2021-06-26 15:23:15 +00:00
*
* @return bool|string
*/
public function fetch(string $uri)
{
$ch = curl_init();
curl_setopt_array($ch, [
2021-06-26 15:23:15 +00:00
CURLOPT_URL => $uri,
CURLOPT_RETURNTRANSFER => 1,
2021-06-26 15:23:15 +00:00
CURLOPT_CONNECTTIMEOUT => 5,
]);
$data = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
throw new HttpFetchException($err);
}
return $data;
}
2019-01-27 10:29:23 +00:00
}