PHP将文件保存到用户计算机 [英] PHP save file to users computer

查看:112
本文介绍了PHP将文件保存到用户计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以在单击添加联系人"按钮时为工作人员创建一个vCard.我将此vCard包含在变量中,但是我不确定接下来如何处理.

I have a script that creates a vCard for members of staff when the 'Add Contact' button is clicked. I have this vCard in a variable, but I'm not really sure what to do with it next.

我认为我的第一个步骤应该是将此文件保存在服务器上?

I take it that my frist step should be to save this file on the server?

我只想弹出一个框,允许人们下载并保存vCard,因此,如果不需要执行此步骤,我想跳过它.

I'd like to just have a box pop up and allow people to download and save the vCard, so if the step about is not necessary I'd like to just skip it.

这里的任何指针都会被应用.

Any pointers here would be appriciated.

谢谢.

推荐答案

如果要在有人请求导出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

这篇关于PHP将文件保存到用户计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆