Php 如何正确下载.vcf文件

Php 如何正确下载.vcf文件,php,download,vcf-vcard,Php,Download,Vcf Vcard,我想知道,如何实现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));

我想知道,如何实现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);
不幸的是,它只提供了.vcf文件中的内容。 如何将此vcard作为下载提供给用户?

put
exit()

您有
标题('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);

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

您确定路径
$path.$file
定义的文件存在吗?打开
错误报告(E_ALL);ini_设置(“显示错误”、“打开”)并重复;-)如果上面指定的代码是整个文件(最好假设它是),那么就不需要退出为什么这是
exit()
?它用于
flush()
行为?text/x-vcard现在被弃用,取而代之的是text/vcard()
$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);