Export array to CSV to disk
tomkralik opened this issue · comments
Hello,
please how can i export array to CSV and
please, how can I export array to CSV file directly to disk with a specific path and file name?
Thank you
Tom
An example of this is available in the README.md: https://github.com/faisalman/simple-excel-php/blob/master/readme.md
Wanted to save CSV on server instead of file to be Automatically Downloaded. Please let me know if this is possible ..
Class is good and easy to use though :)
Does $excel->writer->saveFile('example');
via the Usage
section in the README.md not provide the desired functionality?
May be i am using it in wrong manner. If it can save files over server please provide documentation.
Download in browser is working fine, but i want to save a copy of CSV on server for future references.
Taking a look at the source in 'simple-excel-php/src/SimpleExcel/Writer/BaseWriter.php' the saveFile() method is using a header call to push the file to the users browser. Override that method with the same logic but replace the php:://output and header logic with fwrite() related. This is a good idea for a feature add.
Thanks for Approval and understanding the problem.. Looking forward to see it implemented soon..
Thanks in advance
Here is the change that will do what you want. When calling the saveFile() method pass in a $target (file path) and the system will then save the file to the path instead of triggering a file download. (Make sure your web server user has permissions to write to the provided file path.