I have a situation where web users are able to upload documents to a folder located 1 level up from the website root directory. The documents contain personal information so I figured this was the best way to keep them secure.
Manager users are the only ones that should be able to download these documents so I have set the File Manager path to this folder and everything seems to work well except that the download link in the File Manager will not reference outside the website root. I am having trouble getting my head around how to do this and was hoping someone may have already managed to get this working, has any tips for me, or maybe a better solution... ?
What speaks against simply creating a folder under the root directory and protect it with .htaccess, so it cannot be accessed via browser?
René
Okay, I’ll have to have a look into this as I have not used .htaccess to stop browser access before. I am sure you are not overlooking anything.
Thanks for your input, I appreciate it.
I guess we need to clarify first what we mean by access with the browser. To me, access with the browser means you have a link like www.yourdomain.com/uploaddir/ where people see the content of that directory.
When using the MODx Manager, of course you’re using the browser too. But the file manager is showing the content of the directories by reading it with php. That’s why .htaccess cannot prevent that listing, and you even see the .htaccess files in the file manager, while by access with the browser, the .htaccess file is never visible.
I think I need to understand better now how your web users are uploading those files? I was assuming your web users don’t have access to the MODx Manager, and the file upload for them happens with a plugin or snippet you give them to use?
René
-
☆ A M B ☆
- 24,524 Posts
In any case, a file upload via HTTP (through the browser) is always stored in a temporary location with a temporary name. The meta data for the file is available to PHP as the $_FILES[] array, and the file has to be moved to a permanent location, at which point the temporary file (usually in /tmp, not the absolute URL / but the root filesystem /, on a *nix server) is deleted. So the browser is not uploading the file to its final location, and the temporary file is not accessible to the browser at all. Your processing script can move the file to any location that is accessible to PHP, whether in your webspace or not.
http://il2.php.net/features.file-upload
I’m still not sure if I hear you correctly, but it seems what you want is to allow manager users to download those confidential files the web users did upload, and at the same time hiding those file from web users.
As you’ve found out, in order for manager users to be able to download those files, they have to reside under the document root, or there will be no download link to them.
My solution still is:
a.) storing those files in a directory under the root, so the manager users will get their download link (it seems you know how to upload the files to any folder, so just chose an appropriate one)
b.) protecting that folder from the web users with .htaccess, so they are only visible in the file manager for the manager users, but not for the web users, as they have no access to the manager and therefore also no access to the file manager.
Is there any reason this is not working for you?
René