我建立了一個PHP 5和MySQL的網站,其中有一張表格,用於跟蹤預定的照片拍攝。我想將這些預定「事件」的提要推送到一個ical文件中。從數據庫不能正常工作的動態創建
我原本asked this question,並從S. Gehrig得到了很好的回答。我有一個示例文件正在工作,並且每當我在Dreamweaver中手動調整文件時,都會定期在Google日曆中進行更新。但是,現在我已經添加了從數據庫中動態獲取PHP的功能,它將無法工作。
這裏的PHP:
<?php
require_once('../../_includes/initialize.php');
$ical = " BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN ";
$slots = Slot::find_all();
foreach($slots as $slot) {
$job = Job::find_by_id($slot->job_id);
$start_stamp = strtotime($slot->start);
$end_stamp = strtotime($slot->endtime);
$dtstart = gmdate('Ymd', $start_stamp).'T'. gmdate('His', $start_stamp) . "Z"; // converts to UTC time
$dtend = gmdate('Ymd', $end_stamp).'T'. gmdate('His', $end_stamp) . "Z"; // converts to UTC time
$summary = $job->title;
$ical .= " BEGIN:VEVENT
UID:" . $slot->id . "@homewoodphoto.jhu.edu
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:" . $dtstart . "
DTEND:" . $dtend . "
SUMMARY:" . $summary . "
END:VEVENT ";
}
$ical .= " END:VCALENDAR";
//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=homewoodphoto_master.ics');
echo $ical;
exit;
?>
這個文件的輸出是完全一樣的說明書,硬編碼的版本,我有工作,據我可以告訴。任何人都可以看到爲什麼這不工作?
PS下面是正在工作的文件的代碼 - 我只是將它發佈到我的服務器上,並通過Google日曆中的URL進行了訂閱。當我在第二場比賽中進行硬編碼時,它很快出現在Google日曆中。
<?php
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)); . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20090925T170000Z
DTEND:20090928T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)); . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20090929T170000Z
DTEND:20090930T035959Z
SUMMARY:Camping Trip
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo $ical;
exit;
?>
幫助!
評論者建議我通過刪除標題並回顯$ ical var進行測試。以下是該測試的結果,爲方便您添加換行符:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20090929T212141Z
DTSTART:20091001T230000Z
DTEND:20091001T230000Z
SUMMARY:little title
END:VEVENT
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20090929T212141Z
DTSTART:20090926T230000Z
DTEND:20090927T010000Z
SUMMARY:A big photo shoot
END:VEVENT
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20090929T212141Z
DTSTART:20091003T230000Z
DTEND:20091004T010000Z
SUMMARY:A big photo shoot
END:VEVENT
END:VCALENDAR
謝謝!
在Google日曆中,我收到「設置錯誤」標題和文本錯誤:「我們無法在請求的網址解析日曆。」 – rhodesjason 2009-09-29 21:17:14
Entourage根本無法打開它,iCal說:「這個日曆文件不可讀,沒有事件添加到您的iCal日曆中。」 – rhodesjason 2009-09-29 21:18:03