PHP File Download using POST data via jQuery AJAX

后端 未结 2 1323
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 04:02

So I know there have been a number of similar posts, but I think this is enough of a variation to warrant its own question:

I am building an XLS exporter in PHP and

2条回答
  •  萌比男神i
    2020-12-11 04:41

    This seems like it should be pretty simple, but it all depends on where you're putting those XLS files you're generating. If you're intending that the response to the post should be a "Save File" dialog — that is, the file itself — then all you have to do is make sure the "Content-Disposition" header is set to "attachment", and then stream out the file contents.

    If you're going to generate the file and keep it around, well you're going to have to store it somewhere with an identifier. In that case, you'd just respond with an ordinary page that's got a "download" link, such that that link includes the file identifier. That can trigger either a GET or a POST, and the server would respond to that pretty much as I described above.

    A hidden