开发者

How to download a .vcf file correctly

开发者 https://www.devze.com 2023-01-30 17:57 出处:网络
I\'d like to know, how can I realise a Vcard download. That\'s my current code: $path = \"../../media/resources/\";

I'd like to know, how can I realise a Vcard download. That's my current code:

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

header('Content-Type: text/x-vCard');  
header('Con开发者_运维知识库tent-Disposition: attachment; filename= "'.$file.'"');  
header('Content-Length: '.filesize($path.$file));  
header('Connection: close');  

readfile($path.$file);

Unfortunately, it does only give out the content from the .vcf file. How can I give this vcard to the user as a download?


You have header('Connection: close'); which I would imagine closes the connection before the contents of the file are read. I've removed the line.

I'm not sure about case sensitivity in content-type so I changed it to x-vcard and I changed the content-disposition to inline (a known fix for download issues with IE). Try this:

$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);

Also, make sure the directory "resources" is readable (chmod 755 on the directory) and that the file exists...


put exit()

readfile($path.$file);
exit();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号