CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.

YesSoftware Forums -> CodeCharge -> Tips & Solutions

 Hide and protect your downloadable items

Print topic Send  topic

Author Message

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:

$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)));

4. I add a link to a downloadable item on my site:

You see, the exact location of downloadableitem.jpg is rather hidden, cool ain't it ?

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
View profile  Send private message

Add new topic Subscribe to topic   

These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit

Web Database

Join thousands of Web developers who build Web applications with minimal coding.

Home   |    Search   |    Members   |    Register   |    Login

Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by  and YesSoftware, Inc.