Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2013, 04:25 PM   PM User | #1
boogily
Regular Coder

 
boogily's Avatar
 
Join Date: Jul 2009
Posts: 275
Thanks: 18
Thanked 4 Times in 4 Posts
boogily is an unknown quantity at this point
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;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9lL2ZvYWYuZGYNCml0ZW00LlgtQUJMYWJlbDpGT0FGDQppdGVtNS5Y
 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"
boogily is offline   Reply With Quote
Old 03-07-2013, 04:31 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,658
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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)); 
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 03-07-2013, 08:45 PM   PM User | #3
boogily
Regular Coder

 
boogily's Avatar
 
Join Date: Jul 2009
Posts: 275
Thanks: 18
Thanked 4 Times in 4 Posts
boogily is an unknown quantity at this point
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"
boogily is offline   Reply With Quote
Old 03-07-2013, 08:52 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,658
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
// 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!).
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 03-08-2013, 03:45 AM   PM User | #5
boogily
Regular Coder

 
boogily's Avatar
 
Join Date: Jul 2009
Posts: 275
Thanks: 18
Thanked 4 Times in 4 Posts
boogily is an unknown quantity at this point
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"
boogily is offline   Reply With Quote
Old 03-08-2013, 04:27 AM   PM User | #6
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 906
Thanks: 4
Thanked 212 Times in 211 Posts
tracknut is an unknown quantity at this point
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";
... 
tracknut is offline   Reply With Quote
Old 03-08-2013, 02:25 PM   PM User | #7
boogily
Regular Coder

 
boogily's Avatar
 
Join Date: Jul 2009
Posts: 275
Thanks: 18
Thanked 4 Times in 4 Posts
boogily is an unknown quantity at this point
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"
boogily is offline   Reply With Quote
Old 03-08-2013, 03:49 PM   PM User | #8
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,658
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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:
Quote:
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:
Quote:
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.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.

Last edited by tangoforce; 03-08-2013 at 03:55 PM..
tangoforce is offline   Reply With Quote
Old 03-08-2013, 05:20 PM   PM User | #9
boogily
Regular Coder

 
boogily's Avatar
 
Join Date: Jul 2009
Posts: 275
Thanks: 18
Thanked 4 Times in 4 Posts
boogily is an unknown quantity at this point
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"
boogily is offline   Reply With Quote
Old 03-08-2013, 07:18 PM   PM User | #10
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,658
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 03-08-2013, 07:31 PM   PM User | #11
Rowsdower!
Senior Coder

 
Rowsdower!'s Avatar
 
Join Date: Oct 2008
Location: Some say it's everything.
Posts: 2,015
Thanks: 5
Thanked 395 Times in 388 Posts
Rowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura about
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
Rowsdower! is offline   Reply With Quote
Old 03-08-2013, 08:26 PM   PM User | #12
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,658
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Indeed. Turning on error reporting to full would reveal this when calling the header() function to change the content type.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Tags
.ics, .vcf, iphone, php, vcard

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:26 AM.


Advertisement
Log in to turn off these ads.