obay Posted August 24, 2009 Share Posted August 24, 2009 Hi all, I have a file called excel.php, which exports data into an excel file. Content-Type:application/vnd.ms-excel When I click the link to export, it opens a "download" dialog box, where I can "Run" or "Save" the resulting excel document. This script has seemed to work perfectly for the past months but I have recently noticed that sometimes it doesn't. I noticed that it usually happens when the export data is very large. When I click on the link to export, it just opens a new, empty browser window. I was thinking this is just an issue of PHP's memory limit. So I changed it from 16M to 256M (crazy, right?). But it still doesn't work. I figured later that maybe this isn't a memory problem since it doesn't take long for the page to load, it just doesn't load. What do you think is causing this problem? Note: in case this helps, in my excel.php file, before putting the header()s, I do a base64_decode() on the data to be exported since in the calling page, the data is base64_encode()ed. This is my excel.php: $excel_data = base64_decode($_POST['excel_data']); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Pragma: no-cache'); header('Cache-Control: must-revalidate, post-check=0,pre-check=0'); //need to export as UTF-8, otherwise japanese characters will not show header("Content-Transfer-Encoding: binary"); $excel_data = iconv ( 'UTF-8', 'UTF-16LE//IGNORE', $excel_data ); // assume $excel_data contains UTF-8 encoded header('Content-Type: application/vnd.ms-excel; charset=utf-8'); header('Content-Disposition: attachment; filename='. uniqid('') . '.xls'); header('Content-Length: ' . strlen($excel_data)); //add two characters at the beginning of a file to indicate that it's a UTF-8 document echo chr(255).chr(254); //display the data echo $excel_data; Quote Link to comment https://forums.phpfreaks.com/topic/171577-solved-xls-export-not-working-if-export-data-too-big/ Share on other sites More sharing options...
Grayda Posted August 24, 2009 Share Posted August 24, 2009 If you remove the Content-Type: headers and just let the raw excel data get echoed, are there any error messages in there? Perhaps it's the execution time of the script? Disabling the header changes will let you see if there are any messages. Quote Link to comment https://forums.phpfreaks.com/topic/171577-solved-xls-export-not-working-if-export-data-too-big/#findComment-904814 Share on other sites More sharing options...
obay Posted August 24, 2009 Author Share Posted August 24, 2009 No, there aren't any error messages. I also tried adding echo "test"; die(); before any other statement, and "test" didn't get displayed.. hmmmm... Quote Link to comment https://forums.phpfreaks.com/topic/171577-solved-xls-export-not-working-if-export-data-too-big/#findComment-904815 Share on other sites More sharing options...
obay Posted August 24, 2009 Author Share Posted August 24, 2009 I realized I edited the wrong php.ini. It works now Quote Link to comment https://forums.phpfreaks.com/topic/171577-solved-xls-export-not-working-if-export-data-too-big/#findComment-904928 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.