Prevent accessing files in Drupal files folder directly by following link I have member area on my site, and there i have files available only to members. (also, not to all members, but to members of some role, and also they are further granulated by field condition, but that is a long story :)

But technically, anyone can download a file, if knowing the link to the file.

I would like to prevent downloading files by direct link, or by being logged of site.

It would be perfect if i can execute a script when someone asks for file by direct linking, to check if user is logged in, if he has a role that grants him download.

But if that is not possible, i would like to disable accessing files directly, they should be only accessible by browsing the site.

Thanks for clues
Have a look at hook_file_download


  Control access to private file downloads and specify HTTP headers.
  
  This hook allows modules enforce permissions on file downloads when
  the private file download method is selected. Modules can also provide
  headers to specify information like the file's name or MIME type.