PHP save file to users computer

空扰寡人 提交于 2019-12-05 13:58:02

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;

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

If you have your vcard in a variable, then you can easily force it as a download onto the client with this code:

<?php

header('Content-type: text/vcard');
header('Content-disposition: attachment;filename=vcard.vcf');
echo $vcard_variable;

?>

Try look at the content-disposition header :)

It can force a file download at the client :)

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

<a href="location of the vcard file"><img src="button.jpg"></a>

or are you looking for a different delivery method?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!