File control with htaccess


I want to show a list of files when someone loads - thats’s easy

BUT when someone clicks on one of them (a jpg) I do not want that file to show in the web browser I want it to download onto their computer.

I know this can be done using htaccess I just cannot find out exactly how.

Anyone know???


I’m afraid it’s not so easy. That is browser behavior. .htaccess can help avoid other site linking to your pic. Can it change the browser’s default behavior?


I have it now working with firefox but not IE

I know it can be done - I did it last year and someone on this forum showed me how


In .htaccess use

AddType application/octet-stream .jpg Works in Firefox but not IE, is that what you tried?

Or just

AddType application/octet-stream .jpg

for every jpeg file ((Browser cache must be flushed first))

You could add a note saying ‘Please right click and use save-image’


Rename the jpeg to sample.zzz and then rename it after download back to a jpeg.


ZIP each jpeg as a zip file. You could even password the jpeg if it is a bit dodgy :slight_smile: .
Of course not everybody has an unzipper I suppose.

May I politely ask what you are trying to achieve ultimately? Perhaps that will help someone else to provide a solution.



most users are mac thus no right click

but the project is for a client that wants to give each customer a web page with certain jpgs that they can download only


You must have a bizarre user demographic for your site. Global stats for Macs usually hover around 2% of users (example), and my own Mac users number around 3%.

Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


It’s not a public web site. It is for customers of a photographer. The “users” are all professional publishers and advertising agencies who use only mac’s. 99% of these people use mac’s


I have an iMac (OS9.2) and I’m sure I can get contextual menu’s with a control-click and/or apple-click. :slight_smile:

I didn’t try the Addtype option on my iMac. If I remember the Mac file system doesn’t necessary depend on the file ending like Windows PCs do.

Have you had a trawl through the Mac User groups to see if they can help you.

Perhaps you can use a lo-res thumbnail to display the jpeg on the web page and then link it to the jpeg full size which is zipped up using Zips auto-unpack exe option.
Then Windows PC users can view it. Linux users can unzip it and Mac users can stuffit. :wink:



I was looking for something else and stumbled across this page.
It has a php snippet to download a pdf and I have just tried it with a jpg for both firefox and ie, and it worked okay.

I used:-

/* Using PHP to force a file download
by Chuck Joslin - Awave, Inc.
May, 2005

This short script forces a file download.
For simplicity, it’s intended to be used for a single file.
You can use multiple copies of this file (with unique names)
with different variable values to use it with multiple files.

Use of this script has a side-effect of hiding the location of the
file on your server.

// full server path to file to be downloaded (including filename)

$Path2File = “/home/username/”;

// the filename

$theFileName = “w.jpg”;

//the work gets done here

header (“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header (“Content-Type: application/octet-stream”);
header ("Content-Length: " . filesize($Path2File));
header (“Content-Disposition: attachment; filename=$theFileName”);


Adjust $Path2File and $theFileName as required and save and run with a name say ‘force.php’ or whatever.

I am sure it could be modified to add a number of files.

I do not know if it works on a Mac though.