Jump to content

[SOLVED] xls export not working if export data too big


obay

Recommended Posts

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.