Re: downloading xls files corrupts them

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris Ditty wrote:
I am using php to download xls files on my server.   When I download them, excel is saying they are corrupted.  They are not corrupted on the server itself.  These are simple xls spreadsheets with no formatting in them.

Here is the headers that I am using for the download.  This is happening in both IE and Firefox.
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename("./bidDocs/".$myFile).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("./bidDocs/".$myFile));
readfile("./bidDocs/".$myFile);

Anyone have any suggestions?



actually.. why not simply redirect them to the file?

also here's an alternative

$file = "./bidDocs/".$myFile;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}

if it works don't thank me thank http://php.net/readfile :p

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux