Hello everybody,
I'm using the following script for downloading files from my site.
<?
// these parameters are selected from a database
// $tempfile - path to the temporary file stored on the server
// $filename - desired filename
// $mimetype - usually "audio/mp3" or "audio/ogg"
$size = filesize($tempfile);
header("Content-Length: $size");
header("Content-Type: $mimetype");
header("Content-Disposition: attachment; filename=$filename");
$fh = fopen($tempfile, "r");
fpassthru($fh);
?>
It work's well with IE, Netscape and Mozilla - it sets correct filename and sends the file. But when using Opera (6 in my case) it won't set the filename, it still uses the filename of the script itself (i.e. download.php).
The only solution I've found is using redirect to the file itself, i.e.
<? Header("Location: $tempfile"); ?>
This is a rock solid solution, but this solution has two main disadvantages:
(1) What if I'll want to download some data directly from the database? There won't be any tempfile to redirect to.
(2) The user will know full path to the file. Well, this is not as big problem as (1), but I'd like the user not to know this.
Thank's for your help
Tomas