我正在 PHP 中创建一个 ics 日历事件/约会。创建活动后,可通过超链接下载和导入:
$icsFilename=sprintf("calTruthUniversal%dFile.ics",$randNum);
$fp = fopen($icsFilename, 'w');
fwrite($fp, 'BEGIN:VCALENDAR'."\r\n");
fwrite($fp, "PRODID:-//Truth Universal, LLC//Truth Universal Calendar 70.9054//EN\r\n");
fwrite($fp, "VERSION:2.0\r\n");
fwrite($fp, "CALSCALE:GREGORIAN\r\n");
fwrite($fp, "METHOD:REQUEST\r\n");
fwrite($fp, "BEGIN:VEVENT\r\n");
fwrite($fp, "DTSTART:".$dtstart."\r\n");
fwrite($fp, "DTEND:".$dtend."\r\n");
fwrite($fp, "ORGANIZER;CN=truthuniversal@yahoo.com:mailto:truthuniversal@yahoo.com\r\n");
fwrite($fp, "DESCRIPTION:".$description."\r\n");
fwrite($fp, "LOCATION:".$c_address."\r\n");
fwrite($fp, "SUMMARY:".$c_event."\r\n");
fwrite($fp, "END:VEVENT\r\n");
fwrite($fp, "END:VCALENDAR\r\n");
fclose($fp);
//echo "<br>";
//echo "<hr>";
echo"<a href=\"download.php?icsFile=".$icsFilename."\"><img src=\"../images/icon_cal.png\" border=\"0\"></a><br><br>";
脚本 download.php 设置 headers/content-type 并流式传输文件以供下载:
<?php
$myFile = $_GET['icsFile'];
$size=filesize($myFile);
header("Content-Type: text/calendar; charset=utf-8");
header("Content-Disposition: attachement; filename=".$myFile);
header("Content-Length: ".$size);
header("Content-Transfer-Encoding: binary");
$fh = @fopen($myFile, 'rb');
$theData = fread($fh, $size);
fclose($fh);
echo $theData;
?>
在 iPhone 和 Android 手机上通过超链接下载 ics 文件时,它会被导入手机的日历中。然而,黑莓并没有这样做。它下载文件,但仅在显示此警报后:“无法显示您选择的项目。您要保存该项目吗?” 它没有将文件导入日历。
我什至尝试将 Content-Type 更改为“application/x-rimcalendarevent”,但无济于事。
有没有人有办法解决吗?!?
沮丧的,
乌贾西里