1

A module I'm working on maintains a list of files in the private file system folder in Drupal. I use hook_file_download to control access to these files.

I generate links to these files, which end up like: http://sample.com/system/files/my_folder/file.pdf

My website path is /var/www/sample.com/www and the private folder path is configured to be /var/www/sample.com/private.

Now, if the file is placed is /var/www/sample.com/private/my_folder/file.pdf, everything works fine and I can properly control access to the file and deliver it. However, if my_folder is located elsewhere and symlinked in, then things break. I've tracked part of it down to the PHP function file_exists returning false, which is called in file_download.

I'm not sure where to go from here. Everything I've searched for thusfar indicates that symlinks should work just fine. The permissions on the symlinked directory are OK - the directory is 755 and the files are 644.

What else could this be?

I've tried this on the latest PHP 5.3 and PHP 5.4 with no difference.

EDIT: It's worth mentioning that I can get file_exists to return true if I pass the absolute path to the symlinked file. Drupal is passing a stream wrapper though (private://my_folder/file.pdf). So looks like it could be related to the streamwrapper somehow?

1 Answer 1

1

I kept digging and found it was related to Drupal's stream wrapper implementation, specifically the getLocalPath method. There's already a large Drupal issue for this, which I wouldn't have found with my previous search terms.

Your Answer

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

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