vCard .vcf file download browser support - godaddy [closed]

五迷三道 提交于 2019-12-18 13:38:43

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/5116772/vcard-vcf-file-download-browser-support-godaddy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!