I have files stored outside the public_html folder for security purposes. However, I would like to link to specific files somehow where a user could download one of these files.
I am using a jquery script that allows me to specify a server PATH as an upload folder, and it does upload outside the public_html folder.
The only problem is it requires me to specify a URL to the “upload path” which is used to download the files. I thought I might be able to something like:
public_html/redirect (contains htaccess which forwards all requests to "hiding" folder)
hiding (outside public_html)
A user clicks /redirect/file.doc and they download a file located at hiding/file.doc
Is this possible? If not, how can I give specific file download access to files outside of my public_html directory? I know I’ve seen it done on other scripts before…
You can do this with "php download handler":
You can use method like this one to return file contents and file information headers to users browser, just make sure that nothing else is outputted before this.
I suggest that you put this to separate file and call that for example
download.php.Extending it for basic use:
Warning:
This is basic example and does not take into account that user may try to take some evil advantages of
$_GETthat is not properly sanitized.This means basically that user can for example retrieve
passwdfile or some other sensitive information if certain conditions apply.For example, retrieving
/etc/passwd:Just point browser to
http://server.com/download.php?file=../../../etc/passwdand server returns that file. So before real use you should find out how to properly check and sanitize any user supplied arguments.