tags:

views:

488

answers:

3
A: 

Hi,

for which part of this task do you need help?

The following command prints a file to the user:

http://php.net/manual/en/function.file-get-contents.php

eg:

echo file_get_contents("myfile.csv");

edit

Try to add the following headers to your php-page, which will be called for your ajax call:

header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=\"export.csv\"");
henchman
<?phpsession_start();header ("Content-type: application/csv\nContent-Disposition: \"inline; filename=yourfilename.csv\"");include("config.php");$query = $_SESSION['sqlQuery'];$result = mysql_query($query) or die("Query failed : " . mysql_error());echo "ID,STATUS,CATEGORY,TITLE,DATE,URL\r\n"; //headerwhile($row = mysql_fetch_row($result)) { echo "$row[0],$row[4],$row[3],$row[1],$row[2]\r\n"; //data}?>this is the php. So i need something in the html file like:$.post("exportCsv.php",function(data){ something here to export as a csv file (like to download the .csv file)});
A: 

You can just link to the file (no ajax, no $.post) with the header henchman said. It will download the file. Ajax is ment for javascript to get the file, not to perfom download.

streetpc
A: 

That solution worked a treat - adding the mime and attachment headers - link wanted to open the file in Excel just like it was supposed to do.

Nancy Hastings-Trew