Markie
Posts: 251
|
Posted: 10/15/2008, 7:23 AM |
|
Let's say I store my downloadable items in the folder "downloadthis". This is what I do to protect the contents of this folder and also 'anonymize' the URL:
1. I make a textfile (named .htaccess) with this contents:
#
deny from all
#
and I put it in the folder where my downloadable items reside (for example, "downloadthis").
2. I enable the mod_rewrite module (Apache webserver) and make a new textfile (also named .htaccess) with this contents:
#
DirectoryIndex getfile.php index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^download/(.*) getfile.php?file=$1&filename=$1 [nc]
#
I store this .htaccess file in the rootfolder of my website
3. I make a php file (named getfile.php) with this contents:
<?php
$file = $_GET['file'];
$filename = $_GET['filename'];
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header ("Content-disposition: attachment; filename=".$filename.";");
// Length required for Internet Explorer
header("Content-Length: ".@urldecode(@filesize($file)));
@readfile($file);
?>
4. I add a link to a downloadable item on my site:
http://www.mysite.com/download/downloadableitem.jpg
You see, the exact location of downloadableitem.jpg is rather hidden, cool ain't it ?
Markie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
|