How to load .vcf file correctly

I would like to know how I can implement Vcard download. What is my current code:

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

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

+4
source share
2 answers

You have header('Connection: close'); , which, it seems to me, closes the connection before the contents of the file are read. I deleted the line.

I am not sure about case sensitivity in the content type, so I changed it to x-vcard and I changed the content setting to built-in (a known fix for loading problems in IE). Try the following:

 $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 that the "resources" directory is readable (chmod 755 in the directory) and that the file exists ...

+3
source

put exit()

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

Source: https://habr.com/ru/post/1332356/


All Articles