fmCURL Constructor
__construct($options = array(), $curlOptions = array()
Constructor for fmCURL.
Parameters:
(array) $options Optional parameters
(array) $curlOptions Optional parameters passed to curl()
Returns:
The newly created object.
Example:
$curl = new fmCURL();
fmCURL::curl()
function curl($url, $method = METHOD_GET, $data = '', $options = array())
Make a call to curl()
Parameters:
(string) $url The URL
(string) $method 'GET', 'PUT', 'POST', 'PATCH', 'DELETE', etc.
(string) $data Data to send
(array) $options Optional parameters
Returns:
The data sent back from the host. getErrorInfo() may be used to see if there was an error.
Example:
$curl = new fmCURL();
$curlResult = $curl->curl('https://www.example.com');
Get the contents of example.com
Where is ...
Where is ...
fmCURL::getFile()
function getFile($url, $options = array())
Get the contents of a file, optionally downloading or displaying it inline in the browser.
Parameters:
(string) $url The URL where the file is located
(boolean) $options An array of options:
['action'] One of 3 choices:
get - Return the file in $this->file (default)
download - Send headers download, echo $this->file
inline - Send headers for inline viewing, echo $this->file
['fileName'] The filename to use in the Content-Disposition header if ['action'] == 'download'
['compress'] If 'gzip', compress the file. Can always do it if ['action'] == 'get'.
For ['action'] == 'download' or ['action'] == 'inline', only if caller
supports gzip compression.
Defaults to 'gzip' for ['action'] == 'download' or ['action'] == 'inline',
['compressionLevel'] If ['compress'] =='gzip', then gzip with this compression level
(only valid for 'action' = 'download' or 'inline')
['createCookieJar'] If true, a default cookie jar will be create to store any cookies
returned from the call. Defaults to true.
['retryOn401Error'] If true, a second attempt will be made with the cookie jar returned
from the first attempt. This is necessary for some hosts when 401
is returned the first time (sometimes with FM Data API).
Defaults to false.
['getMimeType'] If true, the file will be written to the tmp directory so that
fmCURL::get_mime_content_type() can be used to properly determine the mime type.
Defaults to true.
Returns:
An JSON-decoded associative array of the API result. Typically:
['response'] If successful:
['url'] The same URL passed in
['mimeType'] The computed mime type (when $options['getMimeType'] is true) otherwise
whatever curl determines
['fileName'] The file name passed in $options['fileName'] or retrieved from the url
['extension'] The file's extension (may be empty)
['size'] The size of the file
['messages'] Array of messages. This mimics what the FM Data API returns.
ALSO: the contents of the file will be stored in $this->file to avoid copying/memory consumption
Example:
$curl = new fmCURL();
$result = $curl->getFile($url);
if (! $curl->getIsError($result)) {
// file contents are in $curl->file *not* $result
...
}
Get the Google logo
Download the Google logo
Download/inline the Google logo
Download the Google logo
Download/inline the Google logo