Monday, May 26, 2008

Export to CSV + PHP

On Client
From the client send the string in csvContent field.
input name="csvContent " type="hidden"

Send the fileName in fileName field.
input name="fileName " type="text"

On the Server

$Content = $_POST['csvContent'];
$filename=$_POST['fileName'];
header('Content-Disposition: attachment; filename='.$filename);
header("Content-type: application/text");
echo $Content;

Set header :
1. Content-Disposition:attachment; filename='fileName'
2. Content-type:application/text

Write the content to the browser.

Result : It will open a save-as dialog on the browser.

No comments: