I am developing a system which allows registered users (who could be anybody) to upload files. I've block mime-types etc. to attempt to restrict the files to .doc, .docx and .pdf types, but for additional security, they are uploaded to a folder outside the webroot.
Other users can then choose to download the files. How do I allow them to do that? Obviously I can't just put in a link to the file, as it's outside the webroot. I'm not sure how to reach the file though! I presume I can use the php file functions to get to the file, but how do I then 'serve it up' to the user who has requested it?
What security implications might all of this have?
Thanks.
Try the following:
This will probably need some more headers to suit your needs, but you should get an idea how this can be used.
See the answers to this similar question: Refer to a file outside the website tree for downloading purposes, which links to the PHP header function manual page.
You need a PHP script that does the following:
You can also use readfile function to do basically the same. Here's an example from PHP's site:
You can put your files directory in root and apply mod rewrite rules to secure and show a virtual path to the users instead of real path.