I am getting a Page not Found error when trying to access a file after configuring the module. Here are my settings on admin/settings/private_download:

Private download directory:
group_files

Htaccess Content:

RewriteEngine on
RewriteBase /system/files/group_files
RewriteRule ^(.*)$ $1 [L,R=301]

File headers (default):
Content-Transfer-Encoding: binary
Cache-Control: max-age=60, must-revalidate

I ran into some confusion regarding the RewriteBase setting. After reading and re-reading the field description for Htaccess Content ("The RewriteBase path must start with "/system/" followed by the file system path directory name and ending with the private download directory name defined above."), I really thought my path should be /system/sites/default/files/group_files, but when I would save the form, I would be given an error. I obliged and fixed my path to /system/files/group_files. (My system path is "sites/default/files".)

Thanks.

CommentFileSizeAuthor
#25 Page Not Found.txt285 bytesurlstwohim3

Comments

johnhanley’s picture

Your configuration appears to be correct--pretty straightforward. I assume mod_rewrite is enabled and clean URLs are already properly working.

As you discovered don't duplicate the whole file system path when defining the RewriteBase path.

Did you check to see if group_files was properly created? You should have received an error message if not, but manually check to confirm.

Upload a file to the private directory and try accessing it without authorization (http://domain.com/system/files/group_files/example.jpg) You should see "Access denied".

Please report back here with your findings.

capellic’s picture

There might be something wrong with my caching.

I re-enabled the module this morning, set the directory from "private" to "group_files", set my perms to "authenticated user" then navigated to the file as a logged in user. Now I get "Access Denied." The odd thing is that the Access Denied page shows me as logged out. Interesting.

I then add "anonymous user" to the permissions, try to access the file and get a "Page Not Found" error -- I just can't win!

When I look at the location of the file being requested, it looks like this:
http://----.com/system/files/group_files/455809.jpg

I then turned off all caching on the Performance page. No change.

capellic’s picture

I just installed and tested on my development environment discovered something that might lead us somewhere.

I installed the module without changing the directory. The "private" folder was created and the .htaccess file was written. I manually placed a file in there, tried to access with and without perms and got the expected results -- great!

But then when I changed the settings to make another folder private -- this folder mapping to an ImageField I had created previously and then went to access the image, I got a "File Not Found" error.

Why the difference? I'm not a Drupal file system expert here, but one difference is that the second test is accessing a file that is in the "files" table. Do we have a path mismatch here?

johnhanley’s picture

I just did another round of testing using your setup:

1) Enabled module and saved settings using default configuration (i.e. directory name: private).
2) Without setting any permissions attempted to access file contained in private directory as "anonymous user" and correctly received "Access denied" message.
3) Granted "access private download directory" permission to "anonymous user", refreshed browser and file now accessible.
4) Revisited settings page and changed private directory name to "group_files" and adjusted .htaccess RewriteBase path according. Directory correctly created.
5) Repeated steps 2 & 3 and experienced the same exact behavior.

I conclude the module is working as expected.

johnhanley’s picture

Status: Active » Closed (fixed)
mkelly’s picture

I wish I could say I'm experiencing similar (good) behaviour, but I'm not:

1) Installed module & granted access to private uploads to authenticated user role.
2) Saved default settings config (/system/files/private)
3) Created a new node via custom content type w/filefield that drops file into sites/default/files/private dir.
4) Logged out.
5) Tried to access /sites/default/files/private/file.jpg - got redirected to /system/files/private/file.jpg and received a "not authorized" message. Good, as expected.
6) Logged in as an authorized/authenticated user.
7) Repeated step #5 - instead of an image I get "The requested page could not be found."

8) Went back into module settings and changed private directory to a different location.
9) Repeated step #5, using the *old* private directory location (now unprotected) - /system/files/private/file.jpg - was able to pull up the image.

Something very funny going on here.

mkelly’s picture

and ... now it's working. Disabled some additional modules. Going to go through them one at a time and see if I can sort out which one was the problem.

johnhanley’s picture

Thanks for your original post and follow-up.

Yeah, I was going to suggest some sort of conflict. I'm curious to hear what you discover.

capellic’s picture

Status: Closed (fixed) » Active
benkewell’s picture

run into the same problem when trying to use private_download to protect the directory of webform uploaded files (i.e. 'webform')
i discover that after saving the configure page for private_download, the file gives a 404 error on access (with proper user login)
but if i go to admin/build/modules and save the module install page again, the download works for directory 'webform'

so i test it with a few more steps and have a interesting finding:

1.) as described above, start with fresh installation, save private directory as 'webform', file url gives 404 error on access

2.) go to admin/build/modules and save module install page again, file url can be downloaded and denied successfully as expected on access

3.) change private directory to a new directory 'test1' and save,
download file under old directory 'webform' : work as expected
download file under new directory 'test1' : 404 error on access

4.) change private directory to a new directory 'test2' and save,
download file under old directory 'webform' : work as expected
download file under new directory 'test1' : 404 error on access
download file under new directory 'test2' : 404 error on access

5.) go to admin/build/modules and save module install page again,
download file under old directory 'webform' : 404 error on access
download file under new directory 'test1' : work as expected
download file under new directory 'test2' : work as expected

6.) change private directory to old directory 'webform' and save,
download file under old directory 'webform' : 404 error on access
download file under new directory 'test1' : work as expected
download file under new directory 'test2' : work as expected

7.) go to admin/build/modules and save module install page again,
download file under old directory 'webform' : work as expected
download file under new directory 'test1' : 404 error on access
download file under new directory 'test2' : 404 error on access

that's very interesting...
i also found that it is only after saving module install page again,
that private_download_file_download() is called on access of a file in working directory
and then gives that 'work as expected' result

i believe it might have something to do with private_download_menu(),
as drupal rebuild menu data when saving the module install page.
still investigating into the problem...

benkewell’s picture

Status: Active » Needs review

i've found the solution to the problem:

in private_download_menu() , change

$items['system/files/%'] = array(
    'access arguments' => array('access private download directory'),
    'page callback' => 'file_download',
    'page arguments' => array(variable_get('private_download_directory', 'private')),
    'type' => MENU_CALLBACK,
);

to

$items['system/files/%'] = array(
    'access arguments' => array('access private download directory'),
    'page callback' => 'file_download',
    'page arguments' => array(2),
    'type' => MENU_CALLBACK,
);

by changing 'page arguments' to array(2) ,
it makes sure that file_download() always check the argument from url as requested file

i'm not sure why the old way isn't working,
but this modification is working well on my website

johnhanley’s picture

Benjamin,

Thanks for your testing and detailed analysis.

Apparently hook_menu() has trouble processing system variable values as page arguments.

Your suggested solution is a good one and I will include it in the next release.

Regards,
John

capellic’s picture

Giving up, couldn't get it to work. I tried the solution in #11 and his ability to get it working may be a red herring due to the weirdness pointed out in #10.

johnhanley’s picture

Status: Needs review » Closed (fixed)

The original poster never followed-up with more information on how to reproduce this issue so I'm going to chalk it up to user error or web server misconfiguration.

capellic’s picture

@Bacteria Man

Sorry for not getting back -- got married in November -- busy, busy! I never got it working, but I'm suspecting it might have something to do with me being on a cloud site -- Rackspace Cloud. They do have some interesting file caching techniques that befuddle me at times.

In the meantime, I found another solution, but I would like to return to this eventually and give it a shot on in my local dev environment in order to rule out hosting issues.

johnhanley’s picture

@capellic,

Congrats on your marriage. :-)

I have to believe it has something to do with your web host because the module works as described with 100's of other installations. That said, I'm willing to tweak the module if it means accommodating more configurations.

Cheers,
John

rlamfink’s picture

If you have fckeditor enabled, the redirect commands all show as one single line on the config page. Exclude the path for private download in fckeditor or switch to plain text and add line breaks between the three lines.
Until I did this, I kept getting the error that the path was incorrect.

johnhanley’s picture

A good and seemingly obvious point. You MUST disable the WYSIWYG editor, which can wreak havoc with plain text.

I personally can't stand WYSIWYG editors and would never use them in my own personal projects, but clients seem to love them. Ugh.

espenbe’s picture

Status: Closed (fixed) » Active

capellic desribes the following in #2:
"I re-enabled the module this morning, set the directory from "private" to "group_files", set my perms to "authenticated user" then navigated to the file as a logged in user. Now I get "Access Denied." The odd thing is that the Access Denied page shows me as logged out. Interesting."

I have the same problem in my installation. I just can't view attached files uploaded using the "private" method in Settings->Filesystem. My installation is "clean". Just a fresh installation and enabled the module "Upload". Then I granted access to authenticated users to be able to view uploaded files. I can upload files without problem, but I can't view them. The files are present on the file system.

What could be wrong? Could it be something with the physical filesystem (e.g. permissions, acl, ...)? As said, I haven't done anything to the Drupal installation except enabling the "upload" module and created one page (node) to test private upload. I've tried to follow some of the advices here in this thread without any luck.

Any suggestions are highly appreciated.

johnhanley’s picture

Private Download doesn't have anything to do with Drupal's private file system setting or node file attachments.

espenbe’s picture

Then I really wonder what is the reason for why this doesn't work. If I grant access to "Anonymous", then I can see the attachments. The log tells me that user Anonymous is trying to see the attachment even if I'm logged in. It appears I'm kicked out since the login form is also being displayed when I try to view an attachment.

agoel@axelerant.com’s picture

So the issue here seems to be with menu caching. Just perform the final settings you want, then clear all caches, and you should be good to go.

johnhanley’s picture

Status: Active » Closed (fixed)
urlstwohim3’s picture

Help Please!
I get Page Not Found when using this code.
My file search.php is located in:

C:\xampp>


Search the Database

Search:

urlstwohim3’s picture

StatusFileSize
new285 bytes

Code

johnhanley’s picture

Sorry, you posted to a closed issue regarding something that doesn't pertain.