Re: downloading xls files corrupts them

From: Date: Mon, 12 Jan 2009 19:30:27 +0000
Subject: Re: downloading xls files corrupts them
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-286126@lists.php.net to get a copy of this message
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

« previous php.general (#286126) next »