简体   繁体   English

如何在不使用 echo / print 的情况下下载 PHP 中生成的 ics 文件

[英]How to download an ics file generated in PHP without using echo / print

I am creating some events on PHP and I'd like to download an.ics file containing these several events to upload them later on my for example, outlook calendar.我正在 PHP 上创建一些事件,我想下载包含这几个事件的 an.ics 文件,以便稍后在我的例如 outlook 日历上上传它们。 With "print" or "echo" at the end it works fine but on the platform it is going to be used, I am not allowed to use these two functions.最后使用“print”或“echo”可以正常工作,但是在将要使用的平台上,我不允许使用这两个功能。 Is there an another way to output this event data? output 这个事件数据还有其他方法吗?

What I have done so far is,到目前为止我所做的是,

            $code = "BEGIN:VCALENDAR\n";
            $code .= "VERSION:2.0\n";
            $code .= "METHOD:PUBLISH\n";
            $code .= "BEGIN:VEVENT\n";
            $code .= "DTSTART:" . date("Ymd\THis\Z", strtotime($start_date_time)) . "\n";
            $code .= "DTEND:" . date("Ymd\THis\Z", strtotime($end_date_time)) . "\n";
            $code .= "LOCATION:" . $location . "\n";
            $code .= "TRANSP: OPAQUE\n";
            $code .= "SEQUENCE:0\n";
            $code .= "UID:\nDTSTAMP:" . date("Ymd\THis\Z") . "\n";
            $code .= "SUMMARY:" . $event['summary'] . "\n";
            $code .= "DESCRIPTION:" . $event['description'] . "\n";
            $code .= "PRIORITY:1\n";
            $code .= "CLASS:PUBLIC\n";
            $code .= "BEGIN:VALARM\n";
            $code .= "TRIGGER:-PT10080M\n";
            $code .= "ACTION:DISPLAY\n";
            $code .= "DESCRIPTION:Reminder\n";
            $code .= "End:VALARM\n";
            $code .= "End:VEVENT\n";
            $code .= "End:VCALENDAR\n";

            header('Content-type:text/calendar');
            header("Content-Description: File Download");
            header('Content-Disposition: attachment; filename="events.ics"');
            header("Content-Type: application/force-download");
            header('Connection: close');
            print $code;
    ```

Since the framework builder was handling the outputs all I needed was to assign the part $code to the variable that is being outputted.由于框架构建器正在处理输出,我所需要的只是将部分 $code 分配给正在输出的变量。

All your answers about using print or echo or downloading file were correct if someone needs to do this in the future.如果将来有人需要这样做,您关于使用打印或回显或下载文件的所有答案都是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM