Last active
August 29, 2015 14:01
-
-
Save technoknol/34319c60627777047768 to your computer and use it in GitHub Desktop.
Add new rows to existing CSV without editing it and Download new one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Author : TechnoKnol | |
* Blog : http://technoknol.blogspot.com | |
* | |
*/ | |
header("Content-type: text/csv"); | |
header("Content-Disposition: attachment; filename=file.csv"); | |
header("Pragma: no-cache"); | |
header("Expires: 0"); | |
$file = fopen("csv.csv","r"); | |
$list = array(); | |
while(! feof($file)) | |
{ | |
$list[] = (fgetcsv($file)); | |
} | |
fclose($file); | |
$list[] = array('name5', 'town5'); | |
$list[] = array('name6', 'town6'); | |
$list = array_filter($list); | |
outputCSV($list); | |
function outputCSV($list) { | |
$output = fopen("php://output", "w"); | |
foreach ($list as $row) { | |
fputcsv($output, $row); | |
} | |
fclose($output); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment