1

For Drupal 7 when going to: admin/config/media/file-system you can set up both a Public and Private File System Path.

Is it possible for files that are within the "Public File System Path" that when they are directly accessed via url that a hook could intercept that file request and decide based on the users role whether to allow or send them to a goto like (drupal_goto('user', array('query' => array('destination' => $pre_alias)));)

I know that the hook_file_download can intercept file requests for private files but if possible I don't want to have to spend this extra time setting up a private area.

1 Answer 1

3

Not as standard, no.

Drupal's .htaccess file has these conditions in it for the main index.php rewrite:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Which basically means requests for physical, existing files are passed through without Drupal's involvement.

To change that behaviour you'd need to override those conditions, either in the root .htaccess or one underneath the files folder itself. For nginx you'd be doing basically the same thing, except the vhost's config file would be the place for the rewrite logic.

Then you'd need to implement a menu callback at the path files which dealt with all incoming requests for files. That callback would invoke a custom hook, which your module(s) would consume to make decisions about whether or not that particular file should be downloadable. If so, you'd invoke a file pass through, if not a 403.

Long story short, it's not a good idea - you'll put a large amount more strain on your server with all those extra bootstraps (every CSS file, every image, every everything). What you're describing is the private file system, it would be much more palatable to use that.

The public file system is designed to be just that - public.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.