php – 无法在Chrome或Firefox中下载生成的.ics文件
发布时间:2020-12-13 16:49:18 所属栏目:PHP教程 来源:网络整理
导读:我通过我的php脚本生成了一个ics文件,它允许我在Safari(6.0.2)中下载.ics文件但在Chrome(23.0.1271.101)和Firefox(17.0.1)中我收到一条错误消息: Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found. .ics文件有效(使用两个单独
我通过我的php脚本生成了一个ics文件,它允许我在Safari(6.0.2)中下载.ics文件但在Chrome(23.0.1271.101)和Firefox(17.0.1)中我收到一条错误消息:
.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' . "rn"; $output .= 'VERSION:2.0' . "rn"; $output .= 'PRODID:-//Medicinska Foreningen Orebro//Biljettbokning//SV-SE' . "rn"; $output .= 'METHOD:PUBLISH' . "rn"; $output .= 'BEGIN:VEVENT' . "rn"; $output .= 'CLASS:PUBLIC' . "rn"; $output .= 'CREATED:' . date('YmdTHis') . "rn"; $description = strip_tags( htmlspecialchars_decode( $event->description ) ); $description = str_replace(array( "n",';' ),array( 'n',';' ),$description); $output .= 'DESCRIPTION:' . $description . "rn"; $output .= 'DTSTART:' . $dateEvent->format('YmdTHisZ') . "rn"; $dateEvent->modify('+4 hour'); $output .= 'DTEND:' . $dateEvent->format( 'YmdTHisZ' ) . "rn"; $output .= 'DTSTAMP:' . $dateEvent->format('YmdTHisZ') . "rn"; $output .= 'LAST-MODIFIED:' . date('YmdTHis') . "rn"; $output .= 'LOCATION:' . $event->location . "rn"; $output .= 'UID:' . $dateEvent->format('YmdTHis') . '-' . md5( $event->title ) . '@' . $_SERVER['SERVER_NAME'] . "rn"; $output .= 'END:VEVENT' . "rn"; $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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |