You are here

function private_file_download in Private 5

Same name and namespace in other branches
  1. 6 private.module \private_file_download()

Implementation of hook_file_download().

File

./private.module, line 198
This is an example illustrating how to restrict access to nodes based on some criterion associated with the user.

Code

function private_file_download($file) {
  $file = file_create_path($file);
  $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
  if ($file = db_fetch_object($result)) {
    $node = node_load($file->nid);
    if ($node->private == 1) {
      if (node_access('view', $node) == FALSE) {
        return -1;
      }
    }
  }
}