5

I need a function in my module for users to download a file from a private filesystem.

$file : "private://sample.csv"

Which function should be used, file_download(), or file_transfer()?

function file_download_page() {
  $file = "private://sample.csv";
  //code for downloading $file
}    

Please provide sample code.

6

You just need to call file_create_url().

It will return an URL that will go through Drupal which will then check the appropriate permiss (if you need custom checks, you need to implement hook_file_download)

| improve this answer | |
  • 2
    For private downloads need file_create_url() and hook_file_download(). This works well. – Johnny Dec 25 '11 at 13:25
1

I use hook_file_download_access:

/**
 * Implement hook_file_download_access().
 */
function YOURMODULENAME_file_download_access($file_item, $entity_type, $entity) {
  global $user;
  return (in_array('hr', $user->roles) || in_array('administrator', $user->roles)) ? TRUE : FALSE;
}
| improve this answer | |
0

Using download module you can download the file. I am using this module

| improve this answer | |

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.