簡體   English   中英

無法在Chrome或Firefox中下載生成的.ics文件

[英]Can't download generated .ics-file in Chrome or Firefox

我通過我的php腳本生成了一個ics文件,它允許我在Safari(6.0.2)中下載.ics文件但在Chrome(23.0.1271.101)和Firefox(17.0.1)中我收到一條錯誤消息:

錯誤6(net :: ERR_FILE_NOT_FOUND):找不到文件或目錄。

.ics文件有效(使用兩個單獨的源進行檢查),我可以在iCal中打開它。 我在這個論壇和其他許多論壇上都遵循了腳本和提示。

這是生成.ics文件的代碼:

        $tz_sthlm = new DateTimeZone( 'Europe/Stockholm' );
        $tz_utc = new DateTimeZone('UTC');
        $dateEvent = new DateTime( $event->datetime, $tz_sthlm );
        $dateEvent->setTimezone( $tz_utc );

        $filename = str_replace('/', '-', $event->webblink);

        $output = '';

        $output .= 'BEGIN:VCALENDAR' . "\r\n";
        $output .= 'VERSION:2.0' . "\r\n";
        $output .= 'PRODID:-//Medicinska Foreningen Orebro//Biljettbokning//SV-SE' . "\r\n";
        $output .= 'METHOD:PUBLISH' . "\r\n";
        $output .= 'BEGIN:VEVENT' . "\r\n";
        $output .= 'CLASS:PUBLIC' . "\r\n";
        $output .= 'CREATED:' . date('Ymd\THis') . "\r\n";

        $description = strip_tags( htmlspecialchars_decode( $event->description ) );
        $description = str_replace(array( "\n", ';' ), array( '\n', '\;' ), $description);

        $output .= 'DESCRIPTION:' . $description . "\r\n";
        $output .= 'DTSTART:' . $dateEvent->format('Ymd\THis\Z') . "\r\n";
        $dateEvent->modify('+4 hour');
        $output .= 'DTEND:' . $dateEvent->format( 'Ymd\THis\Z' ) . "\r\n";
        $output .= 'DTSTAMP:' . $dateEvent->format('Ymd\THis\Z') . "\r\n";
        $output .= 'LAST-MODIFIED:' . date('Ymd\THis') . "\r\n";
        $output .= 'LOCATION:' . $event->location . "\r\n";
        $output .= 'UID:' . $dateEvent->format('Ymd\THis') . '-' . md5( $event->title ) . '@' . $_SERVER['SERVER_NAME'] . "\r\n";
        $output .= 'END:VEVENT' . "\r\n";
        $output .= 'END:VCALENDAR';

        header("Content-Type: text/Calendar;charset=utf-8");
        header('Content-Disposition: inline; filename="' . $filename . '.ics"');
/*      header('Content-Transfer-Encoding: binary');
        header('Expires: -1');
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header('Pragma: public');
        header('Content-Length: ' . mb_strlen( $output, '8bit' ) );
    */
        echo $output;
        exit;

這是輸出

 BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//My Company//SV-SE
 METHOD:PUBLISH
 BEGIN:VEVENT
 CLASS:PUBLIC
 CREATED:20130105T000547
 DESCRIPTION:This is my description.
 DTSTART:20130124T170000Z
 DTEND:20130124T210000Z
 DTSTAMP:20130124T210000Z
 LAST-MODIFIED:20130105T000547
 LOCATION:Top secret
 UID:20130124T210000-c88f2fb3f033284ec886aa15acb9eaee@example.com
 END:VEVENT
 END:VCALENDAR

我在Chrome和Firefox中獲得的原因和錯誤消息的任何想法?

提前謝謝了

由於文件正在發送404標頭狀態,請嘗試放置此標頭:

header('HTTP/1.0 200 OK', true, 200);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM