Creating CSV File
CSv stands for Comma Seperated Values
Following example shows how to create a CSV files.
$filename =”file.csv”;
$content = “Test1,Test2″.”\r\n”;
$content .= “Test1,Test2″.”\r\n”;
$fp = fopen ($filename, “w”);
fwrite ($fp,$content,strlen($content));
fclose($fp);
$filesize = filesize($filename);
header(”Content-type: application/octet-stream”);
header(”Content-Disposition: attachment; filename=$filename”);
header(”Pragma: no-cache”);
header(”Expires: 0″);
$fp1 = fopen($filename,”r”);
fpassthru($fp1);
fclose($fp1);
In the above code, first you need to create file. And the datas are seperated by commas.
And following code prompts the users to save or open the file
header(”Content-type: application/octet-stream”);
header(”Content-Disposition: attachment; filename=$filename”);
header(”Pragma: no-cache”);
header(”Expires: 0″);
