Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder boogily's Avatar
    Join Date
    Jul 2009
    Posts
    275
    Thanks
    18
    Thanked 4 Times in 4 Posts

    PHP generated .ics doesn't open on iPhone

    Hi. I am working on a daunting task. I'm trying to get vCards to download on an iPhone. I found the perfect tutorial: http://mobicontact.info/iphone/downl...from-web-page/

    And here is an actual working version
    http://iphone.mobicontact.info/

    So, it would appear if I set up one static instance this would work. The issue is that I'm using php and set it dynamically. the php will grab the right person's vCard and implement it in this whole system.

    They provided a download with sample files. Here is the sample .ics that was in there that supposedly should work (download vCard on iPhone)
    Code:
    BEGIN:VCALENDAR
    VERSION:2.0
    BEGIN:VEVENT
    DTSTART;TZID=Europe/London:20120708T220000
    DTEND;TZID=Europe/London:20120708T230000
    SUMMARY:Click to download contact to your address book
    DTSTAMP:20120708T203910Z
    ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/directory;
     X-APPLE-FILENAME=iphonecontact.vcf:
     QkVHSU46VkNBUkQNClZFUlNJT046My4wDQpOOkNvbnRhY3Q7aVBob25lOzs7DQpGTjppUGhvbm
     UgQ29udGFjdA0KRU1BSUw7dHlwZT1JTlRFUk5FVDt0eXBlPVdPUks7dHlwZT1wcmVmOmlwaG9u
     ZUBtb2JpY29udGFjdC5pbmZvDQpURUw7dHlwZT1DRUxMO3R5cGU9Vk9JQ0U7dHlwZT1wcmVmOj
     AxMi0zNDUtNjc4OQ0KRU5EOlZDQVJEDQo=
    END:VEVENT
    END:VCALENDAR
    And here is the one that got generated on the fly

    Code:
    BEGIN:VCALENDAR
    VERSION:2.0
    BEGIN:VEVENT
    SUMMARY:Click attached contact below to save to your contacts
    DTSTART;TZID=Europe/London:20130307T084200
    DTEND;TZID=Europe/London:20130307T084201
    DTSTAMP:20130307T084200Z
    ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/directory;
     X-APPLE-FILENAME=13626680661361826726john-doe.vcf:
     QkVHSU46VkNBUkQNClZFUlNJT046My4wDQpOOkRvZTtKb2huOzs7DQpGTjpKb2huIERvZQ0KT1
     JHOkV4YW1wbGUuY29tIEluYy47DQpUSVRMRTpJbWFnaW5hcnkgdGVzdCBwZXJzb24NCkVNQUlM
     O3R5cGU9SU5URVJORVQ7dHlwZT1XT1JLO3R5cGU9cHJlZjpqb2huRG9lQGV4YW1wbGUub3JnDQ
     pURUw7dHlwZT1XT1JLO3R5cGU9cHJlZjorMSA2MTcgNTU1IDEyMTINClRFTDt0eXBlPVdPUks6
     KzEgKDYxNykgNTU1LTEyMzQNClRFTDt0eXBlPUNFTEw6KzEgNzgxIDU1NSAxMjEyDQpURUw7dH
     lwZT1IT01FOisxIDIwMiA1NTUgMTIxMg0KaXRlbTEuQURSO3R5cGU9V09SSzo7OzIgRW50ZXJw
     cmlzZSBBdmVudWU7V29ya3Rvd247Tlk7MDExMTE7VVNBDQppdGVtMS5YLUFCQURSOnVzDQppdG
     VtMi5BRFI7dHlwZT1IT01FO3R5cGU9cHJlZjo7OzMgQWNhY2lhIEF2ZW51ZTtIb2VtdG93bjtN
     QTswMjIyMjtVU0ENCml0ZW0yLlgtQUJBRFI6dXMNCk5PVEU6Sm9obiBEb2UgaGFzIGEgbG9uZy
     BhbmQgdmFyaWVkIGhpc3RvcnlcLCBiZWluZyBkb2N1bWVudGVkIG9uIG1vcmUgcG9saWNlIGZp
     bGVzIHRoYXQgYW55b25lIGVsc2UuIFJlcG9ydHMgb2YgaGlzIGRlYXRoIGFyZSBhbGFzIG51bW
     Vyb3VzLg0KaXRlbTMuVVJMO3R5cGU9cHJlZjpodHRwXDovL3d3dy5leGFtcGxlL2NvbS9kb2UN
     Cml0ZW0zLlgtQUJMYWJlbDpfJCE8SG9tZVBhZ2U+ISRfDQppdGVtNC5VUkw6aHR0cFw6Ly93d3
     cuZXhhbXBsZS5jb20vSm9lL2ZvYWYuZGYNCml0ZW00LlgtQUJMYWJlbDpGT0FGDQppdGVtNS5Y
     LUFCUkVMQVRFRE5BTUVTO3R5cGU9cHJlZjpKYW5lIERvZQ0KaXRlbTUuWC1BQkxhYmVsOl8kIT
     xGcmllbmQ+ISRfDQpDQVRFR09SSUVTOldvcmssVGVzdCBncm91cA0KWC1BQlVJRDo1QUQzODBG
     RC1CMkRFLTQyNjEtQkE5OS1ERTFEMURCNTJGQkVcOkFCUGVyc29uDQpFTkQ6VkNBUkQNCg==
    END:VEVENT
    END:VCALENDAR
    I'm not seeing any red flags there. But when I am trying to open the .php file on an iPhone it doesn't prompt the download contact, but instead just opens a page with a white background and the .ics text on it. A desktop will prompt the download, just like it should and it does on the working version, but the iPhone part just shows that page.

    Any initial thought or ideas or help?
    Joomla Development Company and MN SEO
    "Joomla development from design to SEO"

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    First idea: Show your code. The vcard you've shown isn't much use to anyone here unless they know anything about them. This is a php forum so it would follow that showing php code will help us to help you.

    It sounds to me though like you need to use headers to force your iphones browser to recognise it as a download. In w windows environment most browsers will recognise a file type / mime type and either open it in the browser window (eg a jpg file) or download it (eg a zip file). Sometimes though, the browser doesn't know what to do with one type of file so it pretty much takes a guess and either opens it in the window if its text or prompts you to download it if its not. Clearly what you've shown is text so it probably thinks that the best thing to do is display it.

    You might want to consider the use of these..

    PHP Code:
       header('Content-Type: ' $ctype);
       
    header('Content-Disposition: attachment; filename="' $filename '"');
       
    header('Content-Length: '.($seek_end $seek_start 1)); 
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    Regular Coder boogily's Avatar
    Join Date
    Jul 2009
    Posts
    275
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Thanks for the quick response.
    Code:
    	# Send correct headers      
    	header("Content-type: text/x-vcalendar; charset=utf-8"); 
    					// Alternatively: application/octet-stream
    					// Depending on the desired browser behaviour
    					// Be sure to test thoroughly cross-browser
    
    	header("Content-Disposition: attachment; filename=\"iphonecontact.ics\";");
    
    	# Generate file contents - advanced version
    	# BEGIN:VCALENDAR
    	# VERSION:2.0
    	# BEGIN:VEVENT
    	# DTSTART;TZID=Europe/London:20120617T090000
    	# DTEND;TZID=Europe/London:20120617T100000
    	# SUMMARY:iPhone Contact
    	# DTSTAMP:20120617T080516Z
    	# ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/directory;
    	#  X-APPLE-FILENAME=iphonecontact.vcf:
    	#  QkVHSU46VkNBUkQNClZFUlNJT046My4wDQpOOkNvbnRhY3Q7aVBob25lOzs7DQpGTjppUGhvbm
    	#  UgQ29udGFjdA0KRU1BSUw7VFlQRT1JTlRFUk5FVDtUWVBFPVdPUks6aXBob25lQHRoZXNpbGlj
    	#  b25nbG9iZS5jb20NClRFTDtUWVBFPUNFTEw7VFlQRT1WT0lDRTtUWVBFPXByZWY6KzQ0MTIzND
    	#  U2Nzg5MA0KRU5EOlZDQVJE
    	# END:VEVENT
    	# END:VCALENDAR
    	$jinput = JFactory::getApplication()->input;
    	$vsource = JURI::root().'images/joomd/'.$jinput->get('val');
    
    	echo "BEGIN:VCALENDAR\n";
    	echo "VERSION:2.0\n";
    	echo "BEGIN:VEVENT\n";
    	echo "SUMMARY:Click attached contact below to save to your contacts\n";
    	$dtstart = date("Ymd")."T".date("Hi")."00";
    	echo "DTSTART;TZID=Europe/London:".$dtstart."\n";
    	$dtend = date("Ymd")."T".date("Hi")."01";
    	echo "DTEND;TZID=Europe/London:".$dtend."\n";
    	echo "DTSTAMP:".$dtstart."Z\n";
    	echo "ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/directory;\n";
    //	echo " X-APPLE-FILENAME=iphonecontact.vcf:\n";
    	echo " X-APPLE-FILENAME=".$jinput->get('val').":\n";	
    //	$vcard = file_get_contents("iphonecontact.vcf");		# read the file into memory
    	$vcard = file_get_contents($vsource);		# read the file into memory
    //	echo "val=".$vcard.'\n';
    
    	$b64vcard = base64_encode($vcard);						# base64 encode it so that it can be used as an attachemnt to the "dummy" calendar appointment
    	$b64mline = chunk_split($b64vcard,74,"\n");				# chunk the single long line of b64 text in accordance with RFC2045 (and the exact line length determined from the original .ics file exported from Apple calendar
    	$b64final = preg_replace('/(.+)/', ' $1', $b64mline);	# need to indent all the lines by 1 space for the iphone (yes really?!!)
    	echo $b64final;											# output the correctly formatted encoded text
    	echo "END:VEVENT\n";
    	echo "END:VCALENDAR\n";
    There is what I have for the code
    Joomla Development Company and MN SEO
    "Joomla development from design to SEO"

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    // Alternatively: application/octet-stream

    I'd be trying that one in there myself

    Why? - Because otherwise the browser may see that the content is text and just display it (as it's doing!).
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #5
    Regular Coder boogily's Avatar
    Join Date
    Jul 2009
    Posts
    275
    Thanks
    18
    Thanked 4 Times in 4 Posts
    I got excited, but dang it, that didn't work either. Any clue on a next step on debugging this fiasco?
    Joomla Development Company and MN SEO
    "Joomla development from design to SEO"

  • #6
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,141
    Thanks
    7
    Thanked 257 Times in 256 Posts
    A random shot in the dark... I'm providing calendar items off a site, but frankly don't know if they're working on an iPhone. But the top of my code looks like:

    PHP Code:
    header("Content-Type: text/Calendar");
    header("Content-Disposition: inline; filename=calendar.ics");
    echo 
    "BEGIN:VCALENDAR\n";
    ... 

  • #7
    Regular Coder boogily's Avatar
    Join Date
    Jul 2009
    Posts
    275
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Dang it, that didn't work either. The actual link is
    http://mcneilus.happydogwebproductio...=51&Itemid=187

    and then you have to either click on Alaska or if on a phone select Alaska from the select your region. You'll see the first contact with their option to download for iPhone
    Joomla Development Company and MN SEO
    "Joomla development from design to SEO"

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Well I've just looked at your headers and this is what you're outputting:
    Content-Type: text/html; charset=utf-8

    This is the headers from your site:
    HTTP/1.1 200 OK
    Date: Fri, 08 Mar 2013 15:50:41 GMT
    Server: Apache
    Content-Disposition: attachment; filename="iphonecontact.ics";
    P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
    Cache-Control: no-cache, max-age=1814400
    Pragma: no-cache
    Expires: Fri, 29 Mar 2013 15:50:41 GMT
    Vary: Accept-Encoding
    Keep-Alive: timeout=10, max=30
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/html; charset=utf-8
    And from the demo site:
    HTTP/1.1 200 OK
    Date: Fri, 08 Mar 2013 15:50:30 GMT
    Server: LiteSpeed
    Connection: close
    X-Powered-By: PHP/5.2.17
    Content-Type: text/x-vcalendar; charset=utf-8
    Content-Disposition: attachment; filename="iphonecontact.ics";
    Content-Length: 598
    Note that Disposition and Type are in reverse order on your site.

    I can't be sure that is anything to do with your problem but you need to be as identical as possible.
    Last edited by tangoforce; 03-08-2013 at 03:55 PM.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #9
    Regular Coder boogily's Avatar
    Join Date
    Jul 2009
    Posts
    275
    Thanks
    18
    Thanked 4 Times in 4 Posts
    I'm sure it is the content type... it appears it is getting overwritten somehow. UGH Time to debug that now. I'll post when I get that fixed.

    Sorry if this is a newb question. How did you capture the header of my example page might I ask?
    Joomla Development Company and MN SEO
    "Joomla development from design to SEO"

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Firefox has a few plugins (though I also have my own program). For firefox, (which I used) I have two plugins that monitor the headers:
    1) Live HTTP Headers (which is what I used above)
    2) HttpFox - allows you to inspect the headers, content, post data, cookies etc.

    I wouldn't be without either of them for a language like php.

    Firebug is also capable of inspecting headers but I can never find them when I need them so it's easier to use one of the two mentioned above.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #11
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by boogily View Post
    I'm sure it is the content type... it appears it is getting overwritten somehow. UGH Time to debug that now. I'll post when I get that fixed.

    Sorry if this is a newb question. How did you capture the header of my example page might I ask?
    My shot in the dark... Is your PHP file saved without the BOM and are you certain no output is being sent ahead of your intended header? No blank lines above your <?php opening tag? Error logs would presumably show the failure to send the "text/x-vcalendar" type header if output has already begun before the header() function is fired off.

    If not that, then I'm out of ideas.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Indeed. Turning on error reporting to full would reveal this when calling the header() function to change the content type.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •