PEAR/Structures/DataGrid/Renderer/CSV: Warning: fwrite() expects parameter 1 to be resource
From FVue
Contents
Problem
When trying to render CSV to a file using PHP/PEAR datagrid streaming, I receive this error:
PHP Warning: fwrite() expects parameter 1 to be resource, null given in ./Structures/DataGrid/Renderer/CSV.php on line 232
Environment
- PHP-5.3.2
- PEAR/Structures_DataGrid_Renderer_CSV-0.1.5dev1
Solution
Apply the patch underneath to fix the init() function; this will make CSV.init() look at the `_streamingEnabled' option AFTER having looked at the `saveToFile' option - just as is done at two other places.
--- CSV.php (revision 370) +++ CSV.php (working copy) @@ -142,22 +142,20 @@ function init() { $this->_csv = $this->makeBom(); - if ($this->_streamingEnabled) { - echo $this->_csv; - } else { - if ($this->_options['saveToFile'] === true) { - if ($this->_options['filename'] === false) { - return PEAR::raiseError('No filename specified via "filename" ' . - 'option.'); - } - $this->_fp = fopen($this->_options['filename'], - $this->_options['writeMode']); - if ($this->_fp === false) { - return PEAR::raiseError('Could not open file "' . - $this->_options['filename'] . '" ' . - 'for writing.'); - } + if ($this->_options['saveToFile'] === true) { + if ($this->_options['filename'] === false) { + return PEAR::raiseError('No filename specified via "filename" ' . + 'option.'); } + $this->_fp = fopen($this->_options['filename'], + $this->_options['writeMode']); + if ($this->_fp === false) { + return PEAR::raiseError('Could not open file "' . + $this->_options['filename'] . '" ' . + 'for writing.'); + } + } elseif ($this->_streamingEnabled) { + echo $this->_csv; } }
Advertisement