shovonbugs Posted March 31, 2014 Share Posted March 31, 2014 (edited) I'm trying to export HTML to Excel data I get the HTML and want to use header function in Object Model Core class function, below is my code public function getRefrigHtmlToExcelReport($htmlTableResultSM){ header("Content-type: application/ms-excel"); header("Content-Disposition: attachment;filename=test.xls"); header('Cache-Control: public'); echo $htmlTableResultSM; exit(); } in browser console I get the "$htmlTableResultSM" but no excel file downloaded..Please help me, why header is not work in this class. If I test in a single php file then ot works. Thanks Edited March 31, 2014 by shovonbugs (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted March 31, 2014 Share Posted March 31, 2014 'Classes' are supposed to work as 'models' in the mvc pattern, I suggest you try with a new controller Although.... I am not quite sure why it's not working at the moment Link to comment Share on other sites More sharing options...
shovonbugs Posted March 31, 2014 Author Share Posted March 31, 2014 'Classes' are supposed to work as 'models' in the mvc pattern, I suggest you try with a new controller Although.... I am not quite sure why it's not working at the moment I've also tried into "AdminHomeController.php" which is admin controller....but not response Link to comment Share on other sites More sharing options...
NemoPS Posted March 31, 2014 Share Posted March 31, 2014 Try something like this header('Content-Transfer-Encoding: binary'); header('Content-Type: '.$mimeType); header('Content-Length: '.filesize($file)); header('Content-Disposition: attachment; filename="'.$filename.'"'); $fp = fopen($file, 'rb'); while (!feof($fp)) echo fgets($fp, 16384); exit; Replace variables, of course Link to comment Share on other sites More sharing options...
shovonbugs Posted March 31, 2014 Author Share Posted March 31, 2014 Try something like this header('Content-Transfer-Encoding: binary'); header('Content-Type: '.$mimeType); header('Content-Length: '.filesize($file)); header('Content-Disposition: attachment; filename="'.$filename.'"'); $fp = fopen($file, 'rb'); while (!feof($fp)) echo fgets($fp, 16384); exit; Replace variables, of course I don't see any difference with my code public function getRefrigHtmlToExcelReport($htmlTableResultSM){ header("Content-type: application/ms-excel"); header("Content-Disposition: attachment;filename=test.xls"); header('Cache-Control: public'); echo $htmlTableResultSM; exit(); } here is my code...I'm trying to focus on header function..header function not work. Link to comment Share on other sites More sharing options...
shovonbugs Posted March 31, 2014 Author Share Posted March 31, 2014 I don't see any difference with my code public function getRefrigHtmlToExcelReport($htmlTableResultSM){ header("Content-type: application/ms-excel"); header("Content-Disposition: attachment;filename=test.xls"); header('Cache-Control: public'); echo $htmlTableResultSM; exit(); } here is my code...I'm trying to focus on header function..header function not work. what I am realized that when I use header function in popup some contents are showing before header function...but I do not know how to solve.. Link to comment Share on other sites More sharing options...
NemoPS Posted March 31, 2014 Share Posted March 31, 2014 I'm echoing out with fgets Link to comment Share on other sites More sharing options...
inweb Posted March 31, 2014 Share Posted March 31, 2014 Check what headers are you actually sending to the browser (Web Developer Toolbar - Information - View response headers) - they are likely overwritten. Also replace: header("Content-Disposition: attachment;filename=test.xls");with: header('Content-Disposition: attachment;filename="test.xls"');and add header('Content-Transfer-Encoding: binary');to the beginning as suggested before. Link to comment Share on other sites More sharing options...
Recommended Posts