By adr75 on
Dear Forum,
In Drupal 7, how do I view images using the Private file system, without using an image field? I tend to upload images into my Private files directory using FTP or IMCE, and insert them into the node body using IMCE. Viewing the node, the image url is converted to the private "system etc" path, however the image is not displayed (not found). There don't appear to be any permission settings for viewing private files. In Drupal 6, I was using the private_download module for this. Thank in advance for any help!
Comments
_
afaik, in order to allow access to private files, the files need to be managed by drupal. Though IMCE files are managed, I don't think it provides access control.
So how do you provide the
So how do you provide the access control you're talking about? I got the same issue. In my module I add files and I also add usage info (with the file_usage_add() function) and it all works fine, but I can't get access to them.
EDIT:
Never mind, I found the answer. Solved it by implementing the hook_file_download($uri) in my module and returning file_get_content_headers($file) if the user is logged in. Like this:
return false should be: return -1
Thanks for this code! It saved me a lot of time.
A small correction however, the
return false;in the file_download hook should bereturn -1;in order to keep anonymous users out. So, this code works fine:Just to clarify
Hi,
I am using Drupal 7 with private files and I can upload an image into the body field (both through IMCE and Media plugin), but anonymous users cannot see the image (because it is uploaded into the private file folder).
Will the code provided above allow anonymous users to see the images?
I'm trying to find a solution that will allow me to insert an image directly into the body field that anonymous users can see. I'm using CKEditor for the wysiwyg.
Thanks!
Tom Hale
New Day Web Design
www.newdaywebdesign.com