Downloading File to User Issues

Topics: Developer Forum, User Forum
Sep 26, 2007 at 1:13 AM
Here is some of my code:

----------------
$filename = "ZonalReport" . date('H.i_d.m.y') . ".xlsx";

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");

// now make file
if ($format == 'xlsx')
{
$objWriter = new PHPExcelWriterExcel2007($sheet);
$objWriter->save('php://output');
}
else if ($format == 'xls')
{
$objWriter = new PHPExcelWriterExcel5($sheet);
$objWriter->save('php://output');
}
-------------------

I am trying to create a file with that given $filename and have it so when the user visits the page, they are prompted to download the file (and save it). I can't get this to work - when I try to open the file, it says that the file format or file extension is invalid even though it's .xlsx and i'm using 2007. Perhaps I'm doing something wrong in the code...?
Coordinator
Oct 1, 2007 at 7:14 AM
Is there an option to save this to a temporary location on your server, and then use fpassthru() to send it to the client?
Oct 2, 2007 at 4:50 PM
Edited Oct 2, 2007 at 4:52 PM
I am having the same issue ("file format or file extension is invalid"), my code works locally, but not on a live server. I have tried several browsers all with the same error.
I have compared the phpinfo and the differerences are minor (nothing that should trouble it).

If i open the xlsx files in textpad there are only minor differences - perhaps character encoding issues?

I now do the above, and save it to the server, but when i FTP the file down and open it, I have the same problem...

any ideas?