You are here

function flashnode_file_download in Flash Node 6.3

Same name and namespace in other branches
  1. 5.6 flashnode.module \flashnode_file_download()
  2. 5.3 flashnode.module \flashnode_file_download()
  3. 6.2 flashnode.module \flashnode_file_download()

Implementation of hook_file_download To allow flash node to work with a private file system

File

./flashnode.module, line 1194

Code

function flashnode_file_download($file) {

  // See if this file belongs to flash node by querying database
  $file = file_create_path($file);
  $result = db_query("SELECT fi.*, fl.nid FROM {files} fi INNER JOIN {flashnode} fl ON fi.fid = fl.fid WHERE filepath = '%s'", $file);

  // See if we got a result
  if ($file = db_fetch_object($result)) {

    // Check if the user is allowed to view this node, and if they are, return headers, else return access denied
    $node = node_load($file->nid);
    if (node_access('view', $node)) {
      return array(
        'Content-Type: ' . $file->filemime,
        'Content-Length: ' . $file->filesize,
      );
    }
    else {
      return -1;
    }
  }
}