用PHP制作的will不会出现在谷歌日历中

时间:2015-05-14 09:08:11

标签: php calendar icalendar

我正在尝试使用PHP创建我创建的日历中的ical。

Cal url:https://www.gamingonlinux.com/index.php?module=calendar&view=ical

我使用了验证器,它声称它有效,但当我将其添加到测试中时,谷歌日历中没有任何事件显示。

对我的错误有什么想法?

这是制作ical的代码:

// the iCal date format. Note the Z on the end indicates a UTC timestamp.
define('DATE_ICAL', 'Ymd\THis\Z');

// max line length is 75 chars. New line is \\n

$output = "BEGIN:VCALENDAR\r\nMETHOD:PUBLISH\r\nVERSION:2.0\r\nPRODID:-//Gaming On Linux//Release Calendar//EN\r\n";

$db->pquery("SELECT `id`, `date`, `name`, `comment`, `link`, `best_guess` FROM `calendar` WHERE YEAR(date) = $year AND `approved` = 1 ORDER BY `date` ASC");

// loop over events
while ($item = $db->fetch())
{
    if (empty($item['edit_date']))
    {
        $item['edit_date'] = date("Y-m-d");
    }
    $output .=
    "BEGIN:VEVENT\r\nSUMMARY:{$item['name']}\r\nUID:{$item['id']}\r\nDTSTART:" . date(DATE_ICAL, strtotime($item['date'])) . "\r\nDTEND:" . date(DATE_ICAL, strtotime($item['date'])) . "\r\nLAST-MODIFIED:" . date(DATE_ICAL, strtotime($item['edit_date'])) . "\r\nEND:VEVENT\r\n";
}

// close calendar
$output .= "END:VCALENDAR";

echo $output;

1 个答案:

答案 0 :(得分:0)

原来我错过了标题:

header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=calendar.ical');