How to Upload VCF to WordPress for Download via Media Uploader

Uploading and serving V-Card .vcf files from WordPress is a two step process. Step one is adding the MIME type to WordPress so that you can upload your .vcf file with the WordPress Media Uploader. Step two is using Apache’s AddType (these are instructions for a LAMP stack installation by the way) to set the MIME type to application/octet-stream so that the browser will immediately prompt for download.

Register Allowed Type vcf for WordPress Media Uploader

add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ) {
	// add your extension to the array
	$existing_mimes['vcf'] = 'text/x-vcard';
	return $existing_mimes;

Source: Media Library: Error Saving Media Attachment

Add MIME type to WordPress .htaccess to Force Download

Add the line AddType application/octet-stream vcf to your .htaccess file to force download. This line should be placed BEFORE the WordPress lines:

AddType application/octet-stream vcf

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Source: htaccess edit for vcf / vcard downloading

One thing to note, is that you’re testing a single file you may want to force a refresh. Sometimes the original base64 return of your .vcf file will persist in cache making it seem as if nothing has changed.

That’s it.

Follow these 2 steps and you will be able to successfully upload a .vcf V-Card and allow for it to be downloadable when accessed from your website.

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

3 Responses to “How to Upload VCF to WordPress for Download via Media Uploader”

  1. kevin

    thank you for sharing this information. this is exactly what i needed. explanation was clear and well-written. thanks again.

  2. Darren

    Thank you for posting this! Exactly what I was looking for.


  3. Agence PouipouiDesign

    Thank you *very much* for this, exactly what I was looking for, clear and concise, perfect! 🙂

Leave a Reply