You are here

function flipping_book_file_download in Flipping Book 7

Same name and namespace in other branches
  1. 8 flipping_book.module \flipping_book_file_download()

Implements hook_file_download().

File

./flipping_book.module, line 192
Manage Flipping Book packages into Drupal

Code

function flipping_book_file_download($uri) {
  if (arg(2) != 'flipping_book') {
    return NULL;
  }
  $file_path = drupal_realpath($uri);
  $denied = !file_exists($file_path) || !is_file($file_path) || !user_access('access private flipping_books');

  // Access specifically denied.
  if ($denied) {
    return -1;
  }
  $file = new stdClass();
  $uri_chunks = explode('/', $uri);
  $file->filename = end($uri_chunks);
  $file->filemime = file_get_mimetype($uri);
  $file->filesize = filesize($file_path);

  // Access is granted.
  $headers = file_get_content_headers($file);
  return $headers;
}