Jump to content

PHP VCF file doesnt work on android phone


shahzad429

Recommended Posts

i have a page where user can download vcf file to the phone or PC

www.etdtag.com/etd00

 

 

after downloading Vcard it is working fine on PC and blackberry but when user download Vcad on android and save it to contact he san see unknown entry to phone book with no information.

 

PHP code

<?php

class vcard {
  var $log;
  var $data;  //array of this vcard's contact data
  var $filename; //filename for download file naming
  var $class; //PUBLIC, PRIVATE, CONFIDENTIAL
  var $revision_date;
  var $card;
  
  /*
  The class constructor. You can set some defaults here if desired.
  */
  function vcard() {
    $this->log = "New vcard() called<br />";
    $this->data = array(
      "display_name"=>null
      ,"first_name"=>null
      ,"last_name"=>null
      ,"additional_name"=>null
      ,"name_prefix"=>null
      ,"name_suffix"=>null
      ,"nickname"=>null
      ,"title"=>null
      ,"role"=>null
      ,"department"=>null
      ,"company"=>null
      ,"work_po_box"=>null
      ,"work_extended_address"=>null
      ,"work_address"=>null
      ,"work_city"=>null
      ,"work_state"=>null
      ,"work_postal_code"=>null
      ,"work_country"=>null
      ,"home_po_box"=>null
      ,"home_extended_address"=>null
      ,"home_address"=>null
      ,"home_city"=>null
      ,"home_state"=>null
      ,"home_postal_code"=>null
      ,"home_country"=>null
      ,"office_tel"=>null
      ,"home_tel"=>null
      ,"cell_tel"=>null
      ,"fax_tel"=>null
      ,"pager_tel"=>null
      ,"email1"=>null
      ,"email2"=>null
      ,"url"=>null
      ,"photo"=>null
      ,"birthday"=>null
      ,"timezone"=>null
      ,"sort_string"=>null
      ,"note"=>null
      );
    return true;
  }

  /*
  build() method checks all the values, builds appropriate defaults for
  missing values, generates the vcard data string.
  */  
  function build() {
    $this->log .= "vcard build() called<br />";
    /*
    For many of the values, if they are not passed in, we set defaults or
    build them based on other values.
    */
    if (!$this->class) { $this->class = "PUBLIC"; }
    if (!$this->data['display_name']) {
      $this->data['display_name'] = trim($this->data['first_name']." ".$this->data['last_name']);
    }
    if (!$this->data['sort_string']) { $this->data['sort_string'] = $this->data['last_name']; }
    if (!$this->data['sort_string']) { $this->data['sort_string'] = $this->data['company']; }
    if (!$this->data['timezone']) { $this->data['timezone'] = date("O"); }
    if (!$this->revision_date) { $this->revision_date = date('Y-m-dTH:i:s')."Z"; }
    
  	$this->card = "BEGIN:VCARD\r\n";
    $this->card .= "VERSION:3.0\r\n";
$this->card .= "FN:".$this->data['display_name']."\r\n";
    $this->card .= "N:"
      .$this->data['last_name'].";"
      .$this->data['first_name'].";"
      .$this->data['additional_name'].";"
      .$this->data['name_prefix'].";"
      .$this->data['name_suffix']."\r\n";
$this->card .= "PROFILE:VCARD"."\r\n";
if ($this->data['work_po_box']
    || $this->data['work_extended_address']
    || $this->data['work_address']
    || $this->data['work_city']
    || $this->data['work_state']
    || $this->data['work_postal_code']
    || $this->data['work_country']) {
      $this->card .= "ADR:"
        .$this->data['work_address'].";"
        .$this->data['work_po_box'].";"
        .$this->data['work_city'].";"
        .$this->data['work_country']."\r\n";
    }
if ($this->data['email1']) { $this->card .= "EMAIL;TYPE=WORK:".$this->data['email1']."\r\n"; }

  	if ($this->data['company']) { $this->card .= "ORG:".$this->data['company']."\r\n"; }
if ($this->data['title']) { $this->card .= "TITLE:".$this->data['title']; }
  	$this->card .= "\r\n";
if ($this->data['url']) { $this->card .= "URL:".$this->data['url']."\r\n"; }
  	if ($this->data['office_tel']) { $this->card .= "TEL;TYPE=WORK:".$this->data['office_tel']."\r\n"; }
    if ($this->data['cell_tel']) { $this->card .= "TEL;TYPE=CELL:".$this->data['cell_tel']."\r\n"; }

    
  	//$this->card .= "REV:".$this->revision_date."\r\n";
    $this->card .= "END:VCARD\r\n";
  }
  
  /*
  download() method streams the vcard to the browser client.
  */
  function download() {
    $this->log .= "vcard download() called<br />";
    if (!$this->card) { $this->build(); }
    if (!$this->filename) { $this->filename = trim($this->data['display_name']); }
    $this->filename = str_replace(" ", "", $this->filename);
  	header("Content-type: text/x-vcard");
  	header("Content-Disposition: attachment; filename=".$this->filename.".vcf;");
  	echo $this->card;
    return true;
  }
}

 

 

.htaccess

<Files ~ "\.vcf$">
ForceType text/x-vcard
</Files>

 

 

can anyone please help what i am doing wrong?

thanks in advance for your time and help.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.