Sunday, July 17, 2011

Drupal - Using uploaded files without manually changing file permissions

Short fix, followed by longer explanation:

Go to /admin/settings/file-system , set Download Method to "Private - files are transferred by Drupal", save the settings, and see if you are now able to access the uploaded files.

The longer explanation:

Depending on the setup of the web server, uploaded files will be saved with permissions 644, or 600, or maybe something else. Permissions 644 allow ALL server users to read the files, permissions 600 allow only the user that saved the files to read them.
The thing is - the user that "owns" the files (the one that saves them to disk) is a special one, used only by the web server program to do its work. It's not the account you use to administrate the web site - to login to cpanel or FTP. Because of this, sometimes even when you FTP to the site as admin, you cannot remove the uploaded files.
In my case, the files are saved with permissions 600, AND the user that owns them is not the same user Apache uses. So, the web server program cannot read them. I'm assuming my web hosting company uses different users for PHP processes and Apache processes, and the uploaded files are owned by the PHP user. For me, the simplest solution was to use PHP to read the files back to the user, by setting the download method to "Private - files are transferred by Drupal" in the admin page "/admin/settings/file-system".
Hope this helps.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.