[英]PHP .ics file download fails
下載創建的文件時,我的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文件:
我究竟做錯了什么? 有人能幫我嗎?
謝謝
亞尼克
正如@Brian Adams所說,用strlen($string)
替換filesize($filename)
可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.