Thanx Imar, I'll try it out!
Bob
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Sunday, November 24, 2002 10:28 AM
Subject: RE: Image file download
Hi Bob,
The techniques used for PHP are more or less the same as for ASP. The
trick is to set the content type to application/x-unknown and then dump
the contents of the file to the browser, using readfile in my example.
Here's some PHP code that should work:
<?php
header("Content-type: application/x-unknown");
header("Content-Disposition: tnemhcatta;
filename=proposedFileName.gif");
readfile('test.gif');
?>
(I reversed the word attachment to tnemhcatta because Lyris thinks I am
adding an attachment, which obviously I am not. In your code, replace
tnemhcatta with attachment)
In this example, proposedFileName.gif will be the default name that will
be used to save the file at the client side.
test.gif is the name (and location) of the file you want to send. In this
example, it's in the same folder as the PHP file.
To get this to work, you can't output anything else to the browser,
including spaces etc.
To use this example, create two files, file1.php and downloadFile.php
file1.php
Contains a link to the image downloader, for example:
<a href="downloadFile.php?ID=33">Download Image</a>
downloadFile.php
<?php
// Some logic to retrieve the ID from the QueryString
// And some logic to change the ID to an actual file name and
location, maybe a database lookup etc.
// Of course you can also pass the name of the image to this file
directly.
header("Content-type: application/x-unknown");
header("Content-Disposition: tnemhcatta;
filename=proposedFileName.gif");
readfile(YourFileNameHere);
?>
You can use this trick for other documents, like Word documents as well.
HtH
Imar
> Thanx for all the good responses on this. What I have figured out is
that
the pic opens automatically in the browser because Windows has a file
association between the graphic and IE / Navigator, something that I
really
have no control over, and wouldn't want to change it anyway. Imar - The
server is set up to use PHP - do you know of a way to do it with that?
Thanx,
Bob