duanlingzei0170 2014-05-20 14:12
浏览 24
已采纳

无法使用js或php生成要下载的文件

I know there are a lot of tutorials, but for some reason I am not managing to focus the search to my specific issue.

I want to have a link to download <a href="#" download="cal.ics">click</a>

For some reason it fills the file with all the echo's from my page instead of a string that i can prepare.

What am I missing?

Edit:

I want the file to contain the return of this function:

function createICS(){
header("Content-Type: text/Calendar; charset=utf-8'");
header("Content-Disposition: inline; filename=calendar.ics");
$ical = "BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//Geektike/eventsboard//IL
    BEGIN:VEVENT
    UID:123456789
    SUMMARY:asd
    DTSTART:20140520T210000Z
    DTEND:20140520T220000Z
    LAST-MODIFIED:20111115T103014Z
    LOCATION:here
    DESCRIPTION:cool
    END:VEVENT
    END:VCALENDAR";

return $ical;
exit;
}
  • 写回答

2条回答 默认 最新

  • douchang8758 2014-05-20 14:32
    关注

    This: <a href="#" download="cal.ics">click</a> will need to be this: <a href="#" download="cal.php">click</a>.

    Then create the cal.php file and have this code inside it:

    <?php
      print createICS();
    ?>
    

    (That's as long as the cal.php file has access to the createICS() function, otherwise put that function in to the cal.php file as well).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵
  • ¥15 如何输入双曲线的参数a然后画出双曲线?我输入处理函数加上后就没有用了,不知道怎么回事去掉后双曲线可以画出来
  • ¥50 WPF Lidgren.Network.Core2连接问题
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术
  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp