0

I want to be able to have my Drupal 7 site allow both public and private downloads (see below configuration screen shot).

Config screenshot

It appears that the private directory at: sites/default/files/private is preventing direct access to the files which is what I want and is allowing direct public access to the files within: sites/default/files which is also what I want.

My question is what URL do I use to call the private files so that my function hook_file_download($url) it called and then can decide based on a combination of the directory within the /private directory and the requesting users role whether they have access to view this file?

  • Have a look at the documentation under Accessing Private Files. It appears that the files must be attached to a node to be accessed. – Triskelion Jun 7 '13 at 20:25
1

The function you want to use is file_create_url().

You pass a stream wrapper path to your file, in this case it starts with 'private://'.

The value that you pass to the function is 'private://relative/path/to/file.txt'.

The relative path is based on the private files folder.

1

You can not downlaod the files directly via URL, when files is in private directory structure, This module will help you provide the permission to users to download the private files, hope this will help! https://drupal.org/project/private_files_download_permission

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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