【问题标题】:PHP generating a .php.vcf file instead of .vcf filePHP 生成 .php.vcf 文件而不是 .vcf 文件
【发布时间】:2021-09-13 06:22:31
【问题描述】:

我的 PHP 网站中有一个功能,用户可以在其中为员工下载 vcard 文件,但是生成的文件是 .php.vcf 并且在移动设备上不受支持。如何将文件格式更改为 . vcf,生成vcf的简化PHP代码如下。

function generate_vcard($fn,$ln){
$text = 'BEGIN:VCARD' . "\r\n";
$text .= 'VERSION:3' . "\r\n";
$text .= 'Firstname:'.$fn . "\r\n";
$text .= 'Firstname:'.$fn . "\r\n";
$text .= "END:VCARD"."\r\n";
return $text;
}

$generated_text = generate_vcard('John', 'Smith');
header('Content-Type: text/vcard');
echo $generated_text;

vcard 正在下载,问题在于上面提到的扩展名是“.php.vcf”而不是“.vcf”。

【问题讨论】:

    标签: php vcf-vcard


    【解决方案1】:

    您可以尝试添加内容配置并将文件名放在那里:

    header('Content-Disposition: attachment; filename="filename.vcf"');
    

    查看header() 文档,特别是“示例#1”

    【讨论】:

      猜你喜欢
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多