Hi,
I am adding a feature to my website that will
allow people to download and install and executable file...myfile.exe. This is very simple to do by just creating a link directly to the file. However this file is located outside of the location of the web server. It can be referenced without a problem in PHP.
I have attempted to use the following technique:
- page with list of downloads
(download_list.php) has link to
another script which actually does
the download:
...
<A HREF="<?php echo($file_location); ?>download.php?file=myfile.exe">DOWNLOAD</A>
...
- download page (download.php) forces
the appropriate header to be sent
along with the executable file. It
contains the following code ($filepath
is defined in a header otherwise this
is the only code):
<?php
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=\"$file\"\n");
header("Pragma: no-cache\n");
header("Expires: 0\n");
$fn=fopen("$filepath.$file" , "r");
fpassthru($fn);
?>
Here is what happens when you open the link running on win2000 client w/IE 5.5)...
- File download dialog appears....wants to save "download_list.php" which is the originating script even though I have defined the name differently with $file.
- Click on OK with save checked and it saves the originating page link....
- Click on OK with open checked and another file xfer dialog appears...it wants to save
"download.php?myfile.exe"
- Click on OK on the second dialog with save checked and it actually saves the file... myfile.exe
So it appears that it is initiating 2 transfers and the filenames shown as the target are not what I explicitly specified.
Can anyone help with this?
Thanks,
Mark Johnson
mawajo@home.com