You are here

function responsive_favicons_deliver_file in Responsive Favicons 7

Attempts to send the raw file back in the response.

Parameters

$file: a file object respresenting the icon.

See also

http://cgit.drupalcode.org/favicon/tree/src/DrupalFavicon.php#n145

1 string reference to 'responsive_favicons_deliver_file'
responsive_favicons_menu in ./responsive_favicons.module
Implements hook_menu().

File

./responsive_favicons.delivery.inc, line 36
Responsible for sending icons for common paths automatically requested by certain browsers (even though the HTML does not mention them).

Code

function responsive_favicons_deliver_file($file) {
  if (is_int($file)) {
    drupal_deliver_html_page($file);
    return;
  }
  elseif (!is_object($file) || !is_file($file->uri) || !is_readable($file->uri)) {
    drupal_deliver_html_page(MENU_NOT_FOUND);
    return;
  }
  $headers = array(
    'Content-Type' => mime_header_encode($file->filemime),
    'Content-Disposition' => 'inline',
    'Content-Length' => $file->filesize,
  );

  // Let other modules know the file is being downloaded.
  module_invoke_all('file_transfer', $file->uri, $headers);
  foreach ($headers as $name => $value) {
    drupal_add_http_header($name, $value);
  }
  $fd = fopen($file->uri, 'rb');
  if ($fd !== FALSE) {
    while (!feof($fd)) {
      print fread($fd, DRUPAL_KILOBYTE);
    }
    fclose($fd);
  }
  else {
    watchdog('responsive_favicons', 'Unable to open @uri for reading.', array(
      '@uri' => $file->uri,
    ));
    drupal_deliver_html_page(MENU_NOT_FOUND);
    return;
  }
  drupal_page_footer();
}