My webserver is Windows Server 2003, using IIS 6.0. I am attempting to have my php script send a file to the end user using the header() function in php. Here is what I have:
$attachment['attach_type'] = "application/vnd.ms-excel";
$attachment['path'] = "./files/test.xls";
$attachment['attach_file'] = "test.xls";
header("Content-Type: " . $attachment['attach_type']);
header("Content-Transfer-Encoding: Binary");
header("Content-Length: " . filesize($attachment['path']));
header("Content-Disposition: attachment; filename=" . $attachment['attach_file']);
readfile($attachment['path']);
Now, If I send these headers, the dialog box in windows XP (client side) pops up and asks me if I want to open the file or save it as usual. It has found the correct association, as it displays an icon of MS Excel on the dialog box.
When I click "Save" and select a location and hit ok, it just sits there. It appears as if the file is starting to download, but it is at 0% forever. It just never downloads the file.
I also tried to "Open" the file, and it does the same thing.
Does anyone know what might be wrong? Maybe IIS is misconfigured to send the file?
I'm not sure, This same code works fine on Linux/Apache.
Thanks for the help.