From 0395362d662d5849d46d7b3e880522ac97faee60 Mon Sep 17 00:00:00 2001 From: zynode Date: Sat, 31 May 2008 17:59:21 +0000 Subject: [PATCH] parseCSV 0.4.2 git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@34 339761fc-0c37-0410-822d-8b8cac1f6a97 --- ChangeLog.txt | 23 +++++++++++++++++++++++ examples/download.php | 34 ++++++++++++++++++++++++++++++++++ parsecsv.lib.php | 11 +++++------ 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 examples/download.php diff --git a/ChangeLog.txt b/ChangeLog.txt index f8347f2..0f06c9b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,26 @@ +parseCSV 0.4.2 beta +----------------------------------- +Date: 31-May-2008 + +- IMPORTANT! If you're using the output(), + please note that the first parameter has been + completely removed as it was technically just + useless. Instead, the second parameter + (filename) doubles as its replacement. Simply + put, if filename is not set or null, the + output() method will not output a downloadable + file. Please update your existing code + when using 0.4.2 and later :) + +- Small fix to the headers sent by the output() + method. + +- Added a download example using the output() + method to the examples folder. + +----------------------------------- + + parseCSV 0.4.1 beta ----------------------------------- Date: 29-May-2008 diff --git a/examples/download.php b/examples/download.php new file mode 100644 index 0000000..bc4177f --- /dev/null +++ b/examples/download.php @@ -0,0 +1,34 @@ +auto('_books.csv'); + +# ...or if you know the delimiter, set the delimiter character +# if its not the default comma... +// $csv->delimiter = "\t"; # tab delimited + +# ...and then use the parse() function. +// $csv->parse('_books.csv'); + +# now we have data in $csv->data, at which point we can modify +# it to our hearts content, like removing the last item... +array_pop($csv->data); + +# then we output the file to the browser as a downloadable file... +$csv->output('books.csv'); +# ...when the first parameter is given and is not null, the +# output method will itself send the correct headers and the +# data to download the output as a CSV file. if it's not set +# or is set to null, output will only return the generated CSV +# output data, and will not output to the browser itself. + +?> \ No newline at end of file diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 68785a4..50f6f70 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -4,7 +4,7 @@ class parseCSV { /* - Class: parseCSV v0.4.1 beta + Class: parseCSV v0.4.2 beta http://code.google.com/p/parsecsv-for-php/ @@ -216,20 +216,19 @@ class parseCSV { /** * Generate CSV based string for output - * @param output if true, prints headers and strings to browser - * @param filename filename sent to browser in headers if output is true + * @param filename if specified, headers and data will be output directly to browser as a downloable file * @param data 2D array with data * @param fields field names * @param delimiter delimiter used to separate data * @return CSV data using delimiter of choice, or default */ - function output ($output = true, $filename = null, $data = array(), $fields = array(), $delimiter = null) { + function output ($filename = null, $data = array(), $fields = array(), $delimiter = null) { if ( empty($filename) ) $filename = $this->output_filename; if ( $delimiter === null ) $delimiter = $this->output_delimiter; $data = $this->unparse($data, $fields, null, null, $delimiter); - if ( $output ) { + if ( $filename !== null ) { header('Content-type: application/csv'); - header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); echo $data; } return $data;