Forcing vCard downloads on the web

A vCard is like an electronic business card. VCards are often attached to emails, or placed on the contact page of a website (see my contact page, for example). VCards can be easily imported into Outlook, and clicking a vCard link in OSX will automatically add the contact details to your Apple Address Book.

Putting a vCard on your website ought to be very straightforward: just place the file, with its .vcf extension, onto your web server and put a link to it on your contact page. But, like me, you may run into a problem here. When you click on the link in the web page, you may find that the browser opens the vCard file into the browser window, instead of starting a download

There are 2 different ways to solve this problem. The first one is to modify your web server so that it serves up the correct MIME type for the vCard file in the HTTP header. In Apache, for example, you could set this up in the main MIME type configuration file (if you have access to it) or you can set it in a local .htaccess file by adding the following line:

AddType text/x-vcard .vcf

See this article for more details.

The second way to approach the problem is to setup the HTTP headers dynamically. HTTP headers cannot be set on an HTML page of course: an HTML page will have its own headers. To manipulate the headers explicitly you will need to use a server-side scripting language such as PHP or ASP. A decent PHP script for doing this can be found at elouai.com/force-download.php. Note that it is a good idea to hardcode your vCard filename into the script itself to prevent hackers from hijacking the script.

15 Comments

  1. Thanks! This was helpful

  2. ditto on what dorie said. saved me a good amount of frustration!

  3. Thanks…saved me about 3 hours of time…

  4. any idea how to make this work to download a vCard with mobile Safari on the iPhone?

    even with the force-download script the vCard comes up as text on the iPhone.

  5. Tha-haa-haaaaank Yoo-hoo-hoooou!!!

    I spent 90 minutes trying to figure out what was wrong with my server. After I kludged together a PHP script to solve the problem, I finally found this page. The answer to this relatively common problem is remarkably hard to find. Your explanation was clear and concise. I only wish that I had found it first.

    @Steve as far as I know, as of iPhone 2.1, Safari on iPhone still doesn’t support downloading vCards. That’s what sent me on this hunt.

  6. Thanks! This fixed my problem.

  7. Thanks, this was helpful

  8. This looks like what I need. Thank you. :)
    I’d like to copy and paste the PHP example but I don’t understand what I have to edit in the script to launch my “Vcard.vcf”
    Any info would be greatly appreciated.
    Thank you.
    -Alex

  9. Hi Alex, well if you were using the eLouai script, for example, you would replace the line $filename = $_GET['file']; with $filename = ‘Vcard.vcf’;

    (Leaving it to pull out files from the URL is very insecure anyway as this would let people download any random file from your server).

  10. Hello,

    You have described perfectly the dilemma I’ve been dealing with. I’m trying to post the vcard (for download) with out it leading to html text.

    Your solutions were beyond me. I do not have server or networking experience. I use Dreamweaver MX on a Mac. Here is an example of the html concerning the vcard:
    —————–
       
         <a href=”robwellens.vcf”>vCard</a>
         
    ——————-
    is there some text command I can place somewhere in this to make the card download.

    Thanks for your help.

  11. Hi Rob,

    Unfortunately not, for the reasons I explained in the article: you can’t explicitly set your HTTP headers on a normal HTML page. You could try contacting your hosting provider and ask them to change the MIME type association for .vcf files.

  12. This article was very helpful – thank you.
    I love your website – the comments ‘balloons’ are fantastic.
    Well I’m off to check out some of your other (interesting looking) content.
    Thanks again.
    Tom

  13. THANK YOU !

  14. so, in fact it’s all about a server-side issue. it’s good to have someone else to blame other than myself ;) now all I need to do is upload my folder and see if it works then.

    thanks for the info, mate.

    cheers.

Leave a comment