PHP 将文件保存到用户计算机
我有一个脚本,可以在单击“添加联系人”按钮时为员工创建 vCard。我将此 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?
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.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您希望在有人请求导出 URL 时弹出“文件保存”对话框,则必须使用
“所以否”,您不必先将其另存为服务器上的文件。您可以从变量中提供它。请注意,只要您指定正确的 MIME 类型,您就可以对任何其他数据使用此方法内容类型。
另请参阅 https://en.wikipedia.org/wiki/VCard 和 https://www.ietf.org/rfc/rfc2183.txt
If you want a File Save dialog to pop up when someone requests the export URL, you have to use
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.
Also see https://en.wikipedia.org/wiki/VCard and https://www.ietf.org/rfc/rfc2183.txt
如果您的 vcard 位于变量中,那么您可以使用以下代码轻松地将其强制下载到客户端:
If you have your vcard in a variable, then you can easily force it as a download onto the client with this code:
尝试查看内容处置标头:)
它可以强制在客户端下载文件:)
Try look at the content-disposition header :)
It can force a file download at the client :)
您可以从 PHP 输出 vCard,并使用响应标头设置正确的内容类型。这应该会强制在用户的浏览器上进行下载。我用谷歌搜索并找到了这个例子 。
You can just output the vCard from PHP, setting the proper content-type with a response header. This should force a download on the user's browser. I've googled it and found this example.
如果您在服务器上有该文件,则只需在按钮上有一个指向该文件的链接
,或者您是否正在寻找不同的交付方法?
If you have the file on the server you can just have a link on the button that points to the file
or are you looking for a different delivery method?