23 private $curlOptions = [];
31 if (!function_exists(
'curl_init')) {
32 throw new IOException(
"cURL is required to use RemoteDocument.");
34 if (!isset($curlOptions[CURLOPT_URL])) {
35 throw new IOException(
"No url set in cURL options.");
37 $this->curlOptions = $curlOptions;
40 $filename = basename(parse_url($curlOptions[CURLOPT_URL], PHP_URL_PATH));
42 parent::__construct($mimeType, $isDownload, $filename);
56 $ch = curl_init($this->curlOptions[CURLOPT_URL]);
57 foreach ($this->curlOptions as $key => $value) {
58 curl_setopt($ch, $key, $value);
60 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
61 curl_setopt($ch, CURLOPT_WRITEFUNCTION, [$this,
'write']);
63 $error = curl_error($ch);
66 throw new IOException(
"Error retrieving remote document: "+$error);
70 private function write($ch, $data) {
AbstractFormat is used as base class for specialized documents.
__construct($curlOptions, $isDownload)
Constructor.
FileUtil provides basic support for file functionality like HTTP file upload.
RemoteDocument represents a remote file retrieved via cURL.
IOException signals an exception in i/o operations.
static getMimeType($file)
Get the mime type of the given file.