且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP将文件保存到用户计算机

更新时间:2022-03-04 07:30:25

如果要在有人请求导出URL时弹出文件保存"对话框,则必须使用

If you want a File Save dialog to pop up when someone requests the export URL, you have to use

header("Content-type:text/vcard; charset=utf-8");
header("Content-Disposition: attachment; filename=vcardexport.vcf");
echo $vCardData;

因此,不需要,您不必首先将其另存为服务器上的文件.您可以从变量中提供服务.请注意,只要您为以下内容指定正确的 MIME类型,就可以对其他任何数据使用此方法.内容类型.

So No, you dont have to save it as a file on the server first. You can serve it from the variable. Note that you can use this approach for any other data as long as you specify the right MIME Type for Content-Type.

另请参见 https://en.wikipedia.org/wiki/VCard https://www.ietf.org/rfc/rfc2183.txt