Re: Blocking the direct download of a file
| From: | Jon Anderson | Date: | Mon, 07 May 2007 16:27:18 +0000 |
| Subject: | Re: Blocking the direct download of a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254501@lists.php.net to get a copy of this message | ||
pw wrote:
I have a phtml file that contains a reference to a java archive (jar) file. I only want the archive used in the context of a specific html page. I don't want the archive to be downloaded directly.I can think of two easy ways to do this. If you're using Apache, you could fiddle with the config a little to deny non-local downloads: SetEnvIfNoCase Referer "^http://www.myweb.com/" local_ref=1 <FilesMatch "\.jar"> Order Allow, Deny Allow From env=local_ref </FilesMatch> (Stolen from: http://apache-server.com/tutorials/ATimage-theft.html. Have used something similar, but don't want to dig through my own configs.) Alternately, you can do something like this - similar to your idea, but in this case, the download actually happens from the PHP script: if (strpos($_SERVER['HTTP_REFERER'],'http://www.myweb.com/') === 0) { header('Content-Type: application/java-archive'); readfile('/path/to/real/jarfile.jar'); exit(0); } There are probably lots of other ways to do that kind of thing. jon