By raghukr on
I am migrating my current website to drupal. I am writing a custom module to display some images which are outside document root. In my old implementation, I was using readfile($path) in a file getimage.php to render image and was using it as follows
![]()
Now, I am not sure how to achieve the same thing in drupal. I cannot move the images into document root because of security reasons (only authenticated users should be able to use it).
Any suggestions/links/references welcome.
Thanks in advance.
Comments
Use a menu callback to perform your getimage.php functionallity
You could implement your getimage.php code inside a Drupal menu callback, passing the image name as a parameter. These callbacks can have permissions set, so that only authenticated users can access them.
All about menus & callbacks can be found here: http://drupal.org/node/109131
Don't forget the usual security checks to prevent people trying to guess other filenames!
I can do that (actually I
I can do that (actually I have currently implemented it that way), but I thought there would be a "drupal" way of doing it -- may be using apis like file_transfer(). Thus it would be more secure.
I am not very comfortable with the fact that most of the drupal file apis work only with directories/files within drupal installation.
EDIT:
I fixed the problem myself, but I am updating it with solution for the users who may visit this post because of similar problems.
Basically my initial understanding that drupal file apis work only with directories/files within drupal installation is not true. To make drupal work with files outside installation, file system module has to be setup and files directory has to be set to some dir outside the webroot.
Migrating from joomla to drupal and being a newbie in drupal, I find the community support here very disappointing. I post a problem and get no replies for long time. By then I would have figured it myself, but would have spent(rather wasted) lot of time doing r&d.