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 WordPressRewriteEngine 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.
3 Responses to “How to Upload VCF to WordPress for Download via Media Uploader”
kevin
thank you for sharing this information. this is exactly what i needed. explanation was clear and well-written. thanks again.
Darren
Thank you for posting this! Exactly what I was looking for.
Cheers!
Agence PouipouiDesign
Thank you *very much* for this, exactly what I was looking for, clear and concise, perfect! 🙂