在 PHP 中使用 MySQL 数据库创建动态 iCal

发布于 2024-12-01 06:36:01 字数 751 浏览 0 评论 0原文

我正在尝试根据当前正在查看的事件为数据库中的每个事件创建一个动态 iCal 文件,但由于某种原因它不起作用。有什么想法吗?

$current_event = $db->GetRow(false, "SELECT * FROM event WHERE eventid = ".$_GET['eventid']);

$sql = "SELECT * FROM event WHERE eventid = '". $current_event['eventid'] ."'";
$data = $db->Query($sql);
$regdata = $db->GetRow($data);

$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20101231T230000
DTEND:20110101T01000
SUMMARY:TOO
LOCATION:Downtown
DESCRIPTION:".$current_event['eventid']."
SEQUENCE:0
DTSTAMP:20101125T112600
END:VEVENT
END:VCALENDAR
";

header("Content-Type: text/calendar;");
header("Content-Disposition: inline; filename=eventtooutlook.ics");
echo $ical;
exit;

I am trying to create a dynamic iCal file for each event in my database depending on which event is currently being looked at, but for some reason it's not working. Any ideas?

$current_event = $db->GetRow(false, "SELECT * FROM event WHERE eventid = ".$_GET['eventid']);

$sql = "SELECT * FROM event WHERE eventid = '". $current_event['eventid'] ."'";
$data = $db->Query($sql);
$regdata = $db->GetRow($data);

$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20101231T230000
DTEND:20110101T01000
SUMMARY:TOO
LOCATION:Downtown
DESCRIPTION:".$current_event['eventid']."
SEQUENCE:0
DTSTAMP:20101125T112600
END:VEVENT
END:VCALENDAR
";

header("Content-Type: text/calendar;");
header("Content-Disposition: inline; filename=eventtooutlook.ics");
echo $ical;
exit;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖阳 2024-12-08 06:36:01

还尝试输出第一个

标头(“HTTP/1.0 200 OK”);

我遇到了一个奇怪的问题,我的代码在本地服务器上没问题,但在远程服务器上要么得到 404 要么 500,具体取决于我做了什么,直到我从

header('OK', true, 200) 更改为上面的代码。

原因可能是由于 php 版本 - 无论如何你没有状态标头,所以也许就是这样?

(旁白:你的 DTEND 也缺少 0 )

Also try outputting first

header("HTTP/1.0 200 OK");

I had a weird problem where my code was fine on local server, but then on remote server either got a 404 or 500 depending what I did, until i changed from

header('OK', true, 200) to the above code.

Cause maybe due to Versions of php - anyway you don't have a status header so maybe that is it?

(aside: also your DTEND is missing a 0 )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文