radi8 Posted May 17, 2011 Share Posted May 17, 2011 One more question for you all: We just installed a new Linux Ubuntu V 11.04 server with LAMP (Apache2, PHP 5.3.x, MySQL 5.1.4, etc...) all out of the box stuff. I developed (locally) and app where I am exporting some data from MySQL, putting it into a spreadsheet and then sending the Excel file to the client. This all worked fine in my dev setup. BUT... (you know whats coming next) after deploying the app to the new Web Server, when I attempt to export the data, I am successfully creating the Excel file but rather than opening the download dialogue box, the data is being read and sent to the browser window as text! As I mentioned before, this is a new web server, so there may be something missing on the Apache2 setup, or my code may just be crap. Either way, my head hurts and cannot find out what is happening. Here is my header type configuration: <?php function save($filename, $download=false, $download_filename="") { if (!$download) { return $this->domXML->save($filename); } elseif ($this->domXML->save($filename)) { $realFileInfo = $_SERVER['DOCUMENT_ROOT'].'/truck/admin/export/'.$download_filename; $FileInfo = pathinfo($filename); ob_end_clean(); // fix for IE catching or PHP bug issue header("Pragma: public"); header("Expires: 0"); // set expiration time header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header ("Pragma: no-cache"); //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // browser must download file from server instead of cache // force download dialog header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera header("Content-type: application/x-msexcel"); header("Content-Type: application/download"); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. if ($download_filename == "")$download_filename = "download.xls"; //header("Content-Disposition: attachment; filename=".$download_filename.";"); header("Content-Disposition: attachment; filename=".$realFileInfo.";"); header("Content-Transfer-Encoding: binary"); //header("Content-Length: ".filesize($filename)); header("Content-Length: ".filesize($realFileInfo)); //@readfile($filename); @readfile($realFileInfo); return true; } return false; } ?> Can you see anything wrong? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/236659-need-help-with-download-header/ Share on other sites More sharing options...
radi8 Posted May 17, 2011 Author Share Posted May 17, 2011 I put this in the wrong forum. I don't even know why I was in the AJAX forum t begin with. Does anyone know how to move this to the 'General Help' board? Quote Link to comment https://forums.phpfreaks.com/topic/236659-need-help-with-download-header/#findComment-1216587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.