PHP .ics文件下载失败

时间:2014-04-08 18:43:23

标签: php file download

我的ics创建者在下载创建的文件时失败。 我尝试过以下方法:

function createICS($start, $end, $type, $hrStart, $hrEnd){
$filename = $hrStart."-".$hrEnd." ".$type.".ics";
$string=" 
BEGIN:VCALENDAR 
VERSION:2.0 
PRODID:PHP 
METHOD:REQUEST 
BEGIN:VEVENT
DTSTART:".$start." 
DTEND:".$end."
DESCRIPTION:".$type." 
SUMMARY:".$type." vom ".$hrStart." bis zum  ".$hrEnd."
UID:1
SEQUENCE:0 
DTSTAMP:".date('Ymd')."T".date('His')." 
END:VEVENT
END:VCALENDAR 
"; 
/*!$handle = fopen($filename, 'W');
fwrite($handle, $string);
fclose($handle)*/

/*header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: ". filesize($filename).";");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; "); 
header("Content-Transfer-Encoding: binary");*/

header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\"");
header("Content-Type: application/force-download");
header("Content-Length: " . filesize($filename));
header("Connection: close");

echo $string;

}

但是我只得到了这个响应,而不是.ics文件: enter image description here

我做错了什么?有人能帮助我吗?

由于

Yanick

1 个答案:

答案 0 :(得分:0)

正如@Brian Adams所说,用filesize($filename)替换strlen($string)解决了这个问题。