You are here

function imagecache_external_file_download in Imagecache External 7.2

Same name and namespace in other branches
  1. 8 imagecache_external.module \imagecache_external_file_download()

Implements hook_file_download().

When using the private file system, we have to let Drupal know it's OK to download images from our Imagecache External directory.

Return value

array An array keyed with HTTP Headers.

File

./imagecache_external.module, line 451
Allows the usage of Image Styles on external images.

Code

function imagecache_external_file_download($uri) {

  // Check if the path contains 'imagecache/external'.
  // If not, we fallback to the Image module.
  if (strpos($uri, '/' . variable_get('imagecache_directory', 'externals') . '/') > 0) {
    $info = image_get_info($uri);

    // For safety, we only allow our own mimetypes.
    if (in_array($info['mime_type'], imagecache_external_allowed_mimetypes())) {
      return array(
        'Content-Type' => $info['mime_type'],
        'Content-Length' => $info['file_size'],
      );
    }
  }
  else {

    // Do a fallback to the Image module.
    return image_file_download($uri);
  }
}