PHP VCard不导入/生成

I am working on a php Vcard facility in a site that works fine locally but not on a live server. Locally I am essentially getting the contact details and writing them to a .vcf file on the server ie lewis_cains.vcf which might look like this:

BEGIN:VCARD
VERSION:2.1
N:name;Full
FN:Full name
ORG:Company name
TITLE:Job title
END:VCARD 

etc..

Then on the site I have a direct link to the .vcf file and this links/downloads into my address book perfectly when working locally.

However, I have pushed this onto a live server and it has been outputting a plain text file with the above content. Upon some more research I modified things slightly and have made this method to handle it using a php header:

public static function load_vcard($team_slug){
    $vcard_file = BASE_URL.'vcards/'.$team_slug.'.vcf';
    header('Content-Type: text/vcard');
    header("Content-Disposition: attachment; filename=\"".$team_slug.".vcf\";");
    readfile($vcard_file);
}

Now I'm in a position where it tries to download the file but when I click the link I am getting a 'no importable cards found' message.

Does anyone have any idea as to why this would locally and not live, and then why it doesn't seem to be reading the file correctly?

Many thanks for your help, Lewis.

The way you are loading the vCard file may be the cause of the problem. The vCard file exists on the server, right? Yet, you appear to be using a URL to load the file, instead of a filesystem path. Using a filesystem path may solve the problem:

public static function load_vcard($team_slug){
    $vcard_file = __DIR__.'/vcards/'.$team_slug.'.vcf';
    header('Content-Type: text/vcard');
    header("Content-Disposition: attachment; filename=\"".$team_slug.".vcf\";");
    readfile($vcard_file);
}