gpt4 book ai didi

php - 如何强制用户下载(另存为对话框)刚刚生成的文件?

转载 作者:行者123 更新时间:2023-11-29 04:29:20 25 4
gpt4 key购买 nike

我正在使用查询生成一个文件

SELECT * INTO OUTFILE " . "'c:/myfile.csv'" . " FIELDS TERMINATED BY ','  LINES TERMINATED BY '\n' FROM sample

我的文件现在在 C:/myfile.csv 中。我希望用户下载文件。我怎样才能做到这一点?

最佳答案

你可以:

  • 发送一个 HTTP header ,以表明您要发送的数据类型,并且应该将其下载到一个文件中。
  • 然后,发送该文件的内容。


在 PHP 中,像这样的东西应该可以解决问题:

header('Content-Disposition: attachment; filename="my-file.csv"');  // The name which will be suggested to the user
readfile('c:/myfile.csv'); // outputs the content of the file

关于php - 如何强制用户下载(另存为对话框)刚刚生成的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5503938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com