I export my DHTMLX grid to csv and was able to successfully create the .CSV file. The problem I am facing is that it is not asking the user to save / open the file. I am using the $ .post call from javascript to send a CSV string to PHP and then write this string to csv. For some reason, it does not create an invitation for the user, but it successfully writes the file and saves it on the server. Below is the corresponding code:
JS:
myGrid.csvParser = myGrid.csvExtParser; myGrid.setCSVDelimiter('|'); myGrid.csv.row = "endOfRow"; var gridCsvData = myGrid.serializeToCSV(); $.post( "data/export.php", { csvdata: gridCsvData } );
PHP (export.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 web browser (csv) header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=grid.csv"); header("Pragma: no-cache"); header("Expires: 0");
This code works just fine in the sense that it exports the Grid exactly the way I want and saves it in 'grid.csv'. The problem is that it does not ask the user to save the file. Is this a problem for my PHP headers or do I need to put something in $ .post to report success? Thanks for any help!
ad2387
source share