In my php code, I am retrieving rows from a mySQL db and saving them in to a CSV file. I am hard coding the file name in code. The algorithm is simply as follows:
1. Allow user select excel file.
2. Retrieve rows from table, separate column data with commas and build up strings through concatenation.
3. put the build up into the selected file.
4. Close the file.
However, I wish to show a Save As dialog box for the user to choose the file before I save the built CSV string into the file. The suggestions that I have seen all talk about making it look like a download however in a download the file is already built up before the user saves to local machine. In my case, the file has to be selected first.
I also want the application to be portable if it is moved from a machine whose primary partition is labelled C: to one that is labelled D: so I won’t need to hard code. Thanks.
To cause browsers to download a file (versus just opening it when it’s a known MIME type), you can set the following headers:
Content-disposition: attachment; filename=fname.extI don’t believe there is any way to force browsers to prompt with a Save-As dialog. Each browser handles this differently and it’s normally a local user setting. (i.e. Automatically download to default folder, prompt every time, etc.)
As an alternative, perhaps suggest to your users that they use “Right Click -> Save As…” when they need to clearly specify the download file location and name.