I'm creating a small application in which I want to control permissions to access files.

I can't use a direct link to the file because it can't be publically available on the site (if I am to have control over who can use it).

For a number of reasons, I don't want to use Drupal's default file access (which is essentially the access that the user has to the node that the file is attached to).

So, I need code to be able to output the file to the user's browser if he/she has the appropriate access. Where can I find out how to do that? Thanks!

Comments

kovalev’s picture

In case you won't find anything better, you can change access permissions on the OS level (in Linux) through these functions:
http://us2.php.net/manual/en/ref.exec.php
(or just ``)
════════════════
Sergata - פיתוח תוכנה

somebodysysop’s picture

I guess what I'm asking is how do I render a file? User clicks on link. Link executes function that looks for file, then renders it to browser.

somebodysysop’s picture

http://api.drupal.org/api/function/file_transfer/6

Used this code (utilizing the Media Manager module for storing files as nodes):

/**
 * Display file associated with this node.
 */
function ewb_display_document($nid) {
  $node = node_load($nid);
  $media = media_nodes_load_item($nid);
  $filename = media_filename($media);
  $mime = file_get_mimetype($filename);
  $content_type = "Content-type: ".$mime;
  $file = basename($filename);
  $headers[] = $content_type;
  $headers[] = "Content-Disposition: attachment; filename=\"".$file."\"";
  if (node_access('view', $node)) {
    file_transfer($filename, $headers);
  } else {
    print "You do not have access to this file.";
    watchdog('access denied', 'User may not create not access this document:<strong> '.$filename.'</strong>', $variables = array() , WATCHDOG_WARNING, 'displaydoc/'. $nid);
  }
}