Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to export my DHTMLX Grid to a CSV file. I have the framework for it set up, but am running in an issue where if I try to export more than ~25 rows, it fails. No error message or anything. Below is my code:

Javascript

myGrid.csvParser = myGrid.csvExtParser;
myGrid.setCSVDelimiter('|');
myGrid.csv.row = "endOfRow";

var gridCsvData = myGrid.serializeToCSV();

$.post("data/export.php?csvdata="+gridCsvData);

PHP

$csvData = $_REQUEST['csvdata'];

$csv = explode('endOfRow',$csvData);

$myfile = "grid.csv";

$fh = fopen($myfile, 'w') or die("can't open file");

foreach($csv as $line) {
   fputcsv($fh, explode('|',$line),',','"');
}

fclose($fh);


//Redirect output to a client's web browser (csv)
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=grid.csv");
header("Pragma: no-cache");
header("Expires: 0");

readfile('grid.csv');

Any help is appreciated. I assume it's some kind of size limit problem on the POST and I've tried modifying the limit to 20MB in the .htaccess file. As I said, this works perfectly with only a few rows (<25), but once I try to export any more than that it never generates the .csv file.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I guess that $.post (from jQuery right?) doesn't handle such a huge url. You should add a parameter that can be handle as parameter of the HTTP POST query:

$.post(
  "data/export.php", 
  { 
    csvdata: gridCsvData
  }
);
share|improve this answer
    
Works great thanks man..still having trouble getting it to prompt the user to save the file. Any idea on why that wouldn't be popping up? It is saving on the server just not prompting. –  ad2387 Aug 23 '12 at 15:03
    
Have you tried with application/csv instead of text/csv in the Content-type ? –  j0k Aug 23 '12 at 15:08
    
Yeah, I've gone back and forth between those two. No difference that I could see –  ad2387 Aug 23 '12 at 15:10
    
It might depend on the browser too. You might have a look at these questions/answers: stackoverflow.com/search?q=%5Bphp%5D+force+download –  j0k Aug 23 '12 at 15:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.