function feeds_imagegrabber_validate_download_size in Feeds Image Grabber 7
Same name and namespace in other branches
- 6 feeds_imagegrabber.module \feeds_imagegrabber_validate_download_size()
Validates the size of an file accessible through a http url.
Parameters
$file_url: A string specifying the formatted file url.
$max_size: Maximum size of the file to be downloaded.
$timeout: A float representing the maximum number of seconds the function call may take. The default is 10 seconds. If a timeout occurs, the retuen code is set to the HTTP_REQUEST_TIMEOUT constant.
$max_redirects: An integer representing how many times a redirect may be followed. Defaults to 3.
Return value
An integer code containing filesize in case the file exists and conforms to the size limit, -1 otherwise.
1 call to feeds_imagegrabber_validate_download_size()
- feeds_imagegrabber_scrape_images in ./
feeds_imagegrabber.module - Scrape images from HTML/XML content.
File
- ./
feeds_imagegrabber.module, line 378 - Grabs images for items imported using the feeds module.
Code
function feeds_imagegrabber_validate_download_size($file_url, $max_size, $timeout = 10, $max_redirects = 3) {
$options = array(
'headers' => array(),
'method' => 'HEAD',
'data' => NULL,
'max_redirects' => $max_redirects,
'timeout' => $timeout,
);
$result = drupal_http_request($file_url, $options);
if ($result->code == 200 && isset($result->headers) && is_array($result->headers)) {
//Bug #882992, some servers may return keys with different case.
$headers = array_change_key_case($result->headers);
if (isset($headers['content-length']) && $headers['content-length'] <= $max_size) {
return $headers['content-length'];
}
}
return -1;
}