I just finished writing a file upload utility for a client that enables users to upload files to and download files from the server. My client always wants the user to be presented with a "save file" dialog box as opposed to having the browser displaying the files. To overcome this, I wrote the following script:
global $direc, $fname;
$myfname = $direc . "/" . $fname;
$fp = fopen($myfname,"r");
$buff = fread($fp,filesize($myfname));
Header("Content-Type: application/x-octet-stream");
Header( "Content-Disposition: attachment; filename=$fname");
echo $buff;
Clicking on a file link will open a file with this script in a new window. The only problem is, after downloading the file, this new window remains. I've tried echoing some javascript after echoing $buff in an attempt to close the window, with no success. This wouldn't be such a big deal except that in IE I get an ugly "action canceled" page, which freaks the boss out. Any suggestions on what I can do to display something in that window after the download is completed?