创建可在 WordPress php 中下载的 ICS 文件

发布于 2025-01-18 00:07:05 字数 2280 浏览 2 评论 0原文

我正在尝试使用 php 在 WordPress 中创建 ICS 文件。我不确定我错过了什么我对使用 WordPress 有点陌生我觉得这应该可以工作但由于某种原因我只是收到错误

无法启动'开始:VCALENDARVERSION:2.0PRODID:-//ICalendarCreator//NONSGML//ENBEGIN:VEVENTDTSTART:2022/08/22%208:30%20amDTEND:2022/08/22%204:30%20pmSUMMARY:Flexitec%C2%AE %2 0PVC%20Pipe%20Joining%20and%20Installation位置:布里斯班描述:摘要:Flexitec%C2%AE%20PVC%20Pipe%20Joining%20and%20InstallationEND:VEVENTEND:VCALENDAR'因为该方案没有注册处理程序。

我发现的是,wordpress 可能会做一些与文件头不同的事情?

这是我目前的代码:

`<?php //Give the iCal export a filename
    $filename = urlencode( $title.'-ical-' . date('Y-m-d') . '.ics' );
    $eol = "\r\n";
    $uid = get_the_ID();
    $created_date = get_post_time('Ymd\THis\Z', true, $uid );
    $url = get_the_permalink();
$organiser = "PARTEC";

    //Collect output
    ob_start();

    // Set the correct headers for this file
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=".$filename);
    header('Content-type: text/calendar; charset=utf-8');
    header("Pragma: 0");
    header("Expires: 0");?>

    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//<?php echo $title; ?>
    CALSCALE:GREGORIAN
    X-WR-CALNAME:<?php echo $title.$eol;?>
    BEGIN:VEVENT
    CREATED:<?php echo $created_date.$eol;?>
    UID:<?php echo $uid.$eol;?>
    DTEND;VALUE=DATE:<?php echo $newTime2.$eol; ?>
    DTSTART;VALUE=DATE:<?php echo $newTime.$eol; ?>
    DTSTAMP:<?php echo $created_date.$eol; ?>
    LOCATION:<?php echo $acflocation.$eol; ?>
    DESCRIPTION:<?php echo $eol; ?>
    SUMMARY:<?php echo $title.$eol; ?>
    ORGANIZER:<?php echo $organiser.$eol;?>
    URL;VALUE=URI:<?php echo $url.$eol; ?>
    TRANSP:OPAQUE
    BEGIN:VALARM
    ACTION:DISPLAY
    TRIGGER;VALUE=DATE-TIME:<?php echo $created_date.$eol; ?>
    DESCRIPTION:Reminder for <?php echo (get_the_title()); echo $eol; ?>
    END:VALARM
    END:VEVENT
    END:VCALENDAR`
                            
    <?php //Collect output and echo
    $eventsical = ob_get_contents();
    ob_end_clean();



    ?>
                            <a href="<?php echo $eventsical; ?>">iCal Calendar</a>`

如果有人有任何煽动,我将非常感激。

谢谢你!

I'm trying to create a ICS file in wordpress using php. I'm not sure what I'm missing I am kind of new to using wordpress I feel like this should be working but for some reason I am just getting the error

Failed to launch 'begin:VCALENDARVERSION:2.0PRODID:-//ICalendarCreator//NONSGML//ENBEGIN:VEVENTDTSTART:2022/08/22%208:30%20amDTEND:2022/08/22%204:30%20pmSUMMARY:Flexitec%C2%AE%20PVC%20Pipe%20Joining%20and%20InstallationLOCATION:brisbaneDESCRIPTION:SUMMARY:Flexitec%C2%AE%20PVC%20Pipe%20Joining%20and%20InstallationEND:VEVENTEND:VCALENDAR' because the scheme does not have a registered handler.

All I have found is that it's possible that wordpress does somthing differn't to the headers of the files?

This is my code at the moment:

`<?php //Give the iCal export a filename
    $filename = urlencode( $title.'-ical-' . date('Y-m-d') . '.ics' );
    $eol = "\r\n";
    $uid = get_the_ID();
    $created_date = get_post_time('Ymd\THis\Z', true, $uid );
    $url = get_the_permalink();
$organiser = "PARTEC";

    //Collect output
    ob_start();

    // Set the correct headers for this file
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=".$filename);
    header('Content-type: text/calendar; charset=utf-8');
    header("Pragma: 0");
    header("Expires: 0");?>

    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//<?php echo $title; ?>
    CALSCALE:GREGORIAN
    X-WR-CALNAME:<?php echo $title.$eol;?>
    BEGIN:VEVENT
    CREATED:<?php echo $created_date.$eol;?>
    UID:<?php echo $uid.$eol;?>
    DTEND;VALUE=DATE:<?php echo $newTime2.$eol; ?>
    DTSTART;VALUE=DATE:<?php echo $newTime.$eol; ?>
    DTSTAMP:<?php echo $created_date.$eol; ?>
    LOCATION:<?php echo $acflocation.$eol; ?>
    DESCRIPTION:<?php echo $eol; ?>
    SUMMARY:<?php echo $title.$eol; ?>
    ORGANIZER:<?php echo $organiser.$eol;?>
    URL;VALUE=URI:<?php echo $url.$eol; ?>
    TRANSP:OPAQUE
    BEGIN:VALARM
    ACTION:DISPLAY
    TRIGGER;VALUE=DATE-TIME:<?php echo $created_date.$eol; ?>
    DESCRIPTION:Reminder for <?php echo (get_the_title()); echo $eol; ?>
    END:VALARM
    END:VEVENT
    END:VCALENDAR`
                            
    <?php //Collect output and echo
    $eventsical = ob_get_contents();
    ob_end_clean();



    ?>
                            <a href="<?php echo $eventsical; ?>">iCal Calendar</a>`

Would really appreciate if anyone had any incite.

Thank you!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文