I am working on a site where the admin wants a set of tabular data. I created a module to display this data in the Control Panel, no problems there. My first concern was if there is a preferred method for storing module specific files (a CSV in this case). I settled on adding a directory within the module that stores the CSVs. Is there a better way? Particularly more secure?
My next issue was in forcing the download of the CSV. I would like to use the proper URL structure to hit a download_csv method in my module, set the headers and read out the file. When I do this, the outputted CSV has a full page markup added to the bottom. Here is the code I used in download_csv:
header("Content-Type: application/csv"); header("Content-Disposition: attachment; filename=$filename"); header("Pragma: no-cache"); readfile($filedir.$filename);
Again is there a way to use the proper URL structure and the download_csv method without getting all the "junk" added to the file?