I have a download vCard (.vcf) link on a site. It works locally but not online. Just opens file in browser without downloading. I would rather not have to zip it.
Read around and found I need to put this:
AddType text/x-vcard .vcf
in a .htaccess file. but it's still not working. Am I missing something?
The site is hosted with godaddy. One old thread I read somewhere had a guy who made it work but no more info other than the .htaccess bit.
As a first step, ask Godaddy whether they support AddType
directives and if yes, how. That solution would definitely be preferable.
Alternatively, you may be able to work around it using a primitive PHP script that sends the correct headers.
contact.php (untested):
<?php
# Send correct headers
header("Content-type: text/x-vcard");
// Alternatively: application/octet-stream
// Depending on the desired browser behaviour
// Be sure to test thoroughly cross-browser
header("Content-Disposition: attachment; filename=\"contact.vcf\";");
# Output file contents
echo file_get_contents("contact.vcf");
?>
this would serve the VCF file with the correct header.
Turns out what i was doing was correct just took a while for it to start working. Then when it still did not work in Firefox had to clear offline memory and started working too.
Based on the MIME-Type (in your post text/x-vcard) the browser decides weather to open the file inside the browser or to start a download.
One easy way is to tell the server to offer files ending with .vcf with a ohter MIME-type. Here you should select a type where you can be sure that the browser will always download it:
Try: AddType application/octet-stream vcf