I have a custom module (Drupal 7) where I want to read the contents of a file using file_get_contents($file) in the private directory. Theres a access denied error, as the module accesses as anonymous.

I can access the file via browser via the url created with file_create_url(), but gain no access from my module.

Is there a way to grant my module the permission to open files? Any other ideas are welcome, too.

Thanks, Marc

  • If the file's on the same server use the file system path rather than the url
    – Clive
    Feb 6, 2018 at 22:48
  • Thank you, @Clive. That solved it. PS: It seems like you can't dpm() the result of file_get_content, need to encode that first. That added to my confusion. Feb 7, 2018 at 7:07

1 Answer 1


"Use the file system path rather than the url" - Thanks @Clive, this is the solution.

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.