I’ve read the following question: save file onclick
I understand what it’s saying, but I don’t understand how I’d make that work for an arbitrary file. Would I set the href attribute equal to a PHP script with that information?
Would it be POST or GET? Can I specify? What method within the script would I use to retrieve the filename?
The method of the request has little to do with it. Your request will trigger a response from the server which in turn serves up the file.
It could be a something like
www.site.com/serveFile.php?file=foo.txt. Where you are specifying the file to serve up as a GET parameter.Then in code you could retrieve the file name (or some numeric identifier, or some date range used in retrieving data from the database to serve up CSV content), use that variable, generate content, set the headers. All there is to it. Think the post you linked explains the mechanics of serving the content with the correct disposition for a download (save as).