'Creating an ICS file that is downloadable in WordPress php

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!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source