karldesign Posted March 12, 2008 Share Posted March 12, 2008 Trying to find an answer for this, so hope you can all help... I have an events calendar on a website that I would like users to be able to download an iCal/Outlook calendar reminder. I have created the file by using php: $fileid = $_GET['id']; $filename = $fileid.".ics"; $fileopen = fopen($filename, 'w') or die("can't open file"); $filecontent = "BEGIN:VCALENDAR VERSION:2.0 METHOD:PUBLISH BEGIN:VEVENT ORGANIZER: DTSTART;VALUE=DATE:$starts DTEND;VALUE=DATE:$ends LOCATION:location URL:url TRANSP:TRANSPARENT SEQUENCE:0 UID:111 DTSTAMP:20080117T102312Z DESCRIPTION:test SUMMARY:test PRIORITY:5 X-MICROSOFT-CDO-IMPORTANCE:1 CLASS:PUBLIC END:VEVENT END:VCALENDAR"; fwrite($fileopen, $filecontent); fclose($fileopen); The problem is, when a user downloads this file, it only shows in the browser (text) and does not attempt to download the .ics file... Any help would be great! Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 12, 2008 Share Posted March 12, 2008 You could use Javascript to open a new window, force a save, then close the new window. I've done that before. I'm sure SOMEONE will rant and rave about that, but it's A solution. Quote Link to comment Share on other sites More sharing options...
karldesign Posted March 12, 2008 Author Share Posted March 12, 2008 would rather not use javascript were possible... Quote Link to comment Share on other sites More sharing options...
haku Posted March 12, 2008 Share Posted March 12, 2008 Google "php force download". There are a number of scripts out there that can do this for you. Quote Link to comment Share on other sites More sharing options...
karldesign Posted March 12, 2008 Author Share Posted March 12, 2008 Yeh, tried this, but unfortunately, I cannot send any headers... Quote Link to comment Share on other sites More sharing options...
haku Posted March 12, 2008 Share Posted March 12, 2008 Why can't you send headers? If you can't send headers, then you wont be able to force a download. You will need to require the user to open the file then to save it as the required file type manually. Quote Link to comment Share on other sites More sharing options...
karldesign Posted March 12, 2008 Author Share Posted March 12, 2008 i get the 'headers already sent' error when i try using them again... Quote Link to comment Share on other sites More sharing options...
haku Posted March 12, 2008 Share Posted March 12, 2008 Then the problem isn't that you cant send headers, the problem is that you put your code together wrongly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.