如何正确下载.vcf文件 [英] How to download a .vcf file correctly

查看:124
本文介绍了如何正确下载.vcf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何实现Vcard下载。
这是我当前的代码:

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('Content-Disposition: attachment; filename= "'.$file.'"');  
header('Content-Length: '.filesize($path.$file));  
header('Connection: close');  

readfile($path.$file);

不幸的是,它仅给出.vcf文件中的内容。
如何将此vcard下载给用户?

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

推荐答案

您有 header('Connection:close'); 我想它会在读取文件内容之前关闭连接。我已经删除了这一行。

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.

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

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

还要确保目录 resources可读(目录中的chmod 755),并且文件存在...

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

这篇关于如何正确下载.vcf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆