Php save file to user's computer

I have a script that creates a business card for employees when the "Add Contact" button is clicked. I have vCard in a variable, but I'm not quite sure what to do next.

I believe that my first step should be to save this file on the server?

I would just like to open the window and let people download and save the business card, so if this step is not needed, I would just skip it.

Any pointers here will be indicated.

Thanks.

+4
source share
5 answers

If you want the Save File dialog box to appear when someone asks for the export URL, you should use

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

So no, you do not need to save it as a file on the server first. You can serve it from a variable. Note that you can use this approach for any other data as long as you specify the correct MIME type for Content-Type.

Also see https://en.wikipedia.org/wiki/VCard and https://www.ietf.org/rfc/rfc2183.txt

+7
source

If you have a vcard in a variable, you can easily get it loaded onto the client with this code:

 <?php header('Content-type: text/vcard'); header('Content-disposition: attachment;filename=vcard.vcf'); echo $vcard_variable; ?> 
+2
source

Try to see the content title :)

It can force download a file on the client :)

+1
source

You can simply infer vCard with PHP by setting the correct content type with the response header. This should force download in the user's browser. I searched for it and found this example .

+1
source

If you have a file on the server, you can simply provide a link to a button pointing to the file

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

Or are you looking for another delivery method?

0
source

Source: https://habr.com/ru/post/1390073/


All Articles