如何正确下载.vcf文件

dam*_*zzi 5 php vcf-vcard download

我想知道,我怎样才能实现Vcard下载.这是我目前的代码:

$path = "../../media/resources/";  
$file = "someName.vcf";  

header('Content-Type: text/x-vCard');  
header('Content-Disposition: attachment; filename= "'.$file.'"');  
header('Content-Length: '.filesize($path.$file));  
header('Connection: close');  

readfile($path.$file);
Run Code Online (Sandbox Code Playgroud)

不幸的是,它只提供.vcf文件中的内容.如何将此vcard作为下载提供给用户?

Bre*_*len 4

我想你header('Connection: close');会在读取文件内容之前关闭连接。我已经把线去掉了

我不确定内容类型是否区分大小写,因此我将其更改为 x-vcard,并将内容配置更改为内联(针对 IE 下载问题的已知修复)。尝试这个:

$path = "../../media/resources/";  
$file = "Toni_Junas.vcf";  

header('Content-Type: text/x-vcard');  
header('Content-Disposition: inline; filename= "'.$file.'"');  
header('Content-Length: '.filesize($path.$file));  

readfile($path.$file);
Run Code Online (Sandbox Code Playgroud)

另外,请确保目录“resources”可读(目录上的 chmod 755)并且该文件存在...