Active
Project:
Protected Download (downld)
Version:
5.x-1.0
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
3 Jan 2009 at 10:47 UTC
Updated:
27 Apr 2011 at 19:56 UTC
I needed this for Drupal 6 but I solved it with just using .htaccess (BTW: IIS 6 using isapi_rewrite3)
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteRule ^(.*)$ /index.php?q=system/files%{REQUEST_URI} [U,L,QSA]
Comments
Comment #1
fletchgqc commentedBrilliant idea, thanks a lot! Used a modified version.
This is a simple way to produce a few protected files with CCK instead of having to use upload-related modules.
Tip for anyone debugging - change the end to [L,QSA,R=301] - this allows you to see where you're being redirected to.
Comment #2
highvoltage commentedCould you elaborate a bit more about how to go about this for drupal 6? Does it still work by file directory?
Comment #3
attiks commented#2 It should work with D6, you only have to create a .htaccess file inside the directory with the following content
This will route all request for the files inside the directory to Drupal, so Drupal can see if a user has the appropriate permissions.
Comment #4
giorgio79 commentedI tried it but the file can be still downloaded for me with an anonymous user. Even though I placed this htaccess in the specific files directory.
Comment #5
joachim commentedSame here.
The htaccess correctly sends the user via drupal to get the file (though -- it fails with Drupal in a subfolder btw).
But then there is no access control on that file in Drupal.
Comment #6
joachim commentedAh, I've found the problem.
This redirects public files via Drupal, but you need Drupal to actually decide whether to serve the file or not.
If you're using upload module and some kind of node access system, then access will be restricted.
If like me, you're using a CCK filefield, then you need something else to actually restrict.
Something like this in a custom module:
Comment #7
xjmInteresting; tracking.
Comment #8
joachim commentedMistake in my code above -- the hook should return NULL rather than 1 to allow access.
Here's the updated version -- though it should be noted I've not actually got this to work, as I was tangled up in trouble with htaccess at the point the client changed their mind! ;)
Comment #9
gausarts commentedSubscribing. Thanks
Comment #10
izmeez commentedsubscribing
Comment #11
xjm#3 almost works for me, but not quite. Drupal is in a subdirectory, so I have the following:
Paths are being rewritten to this:
/d6/index.php?q=system/files/d6/sites/default/files/subdir/filename.txtThey should be rewritten to this:
/d6/index.php?q=system/files/subdir/filename.txtIf I enter the latter URL manually, access to files is properly allowed or denied according to node access.
Edit: Here is what works for me:
where subdir is the name of the specific subdirectory of files/ my protected files (and this .htaccess) are in.
Comment #12
ikeigenwijs commentedtracking
Comment #13
maulwuff commentedgreat!
I've been using
using FileField and a subfolder: site/defaul/files/fileFieldFolder