<?php 
header("Content-Type: text/x-vcard; charset=utf-8'");
header("Content-Disposition: inline; filename=" . $user['Profile']['first_name'] . " " . $user['Profile']['last_name'] . ".vcf");

echo "BEGIN:VCARD\n";
echo "VERSION:3.0\n";
echo "N:" . $user['Profile']['last_name'] . ";" . $user['Profile']['first_name'] . "\n";
echo "FN:" . $user['Profile']['first_name'] . " " . $user['Profile']['last_name'] . "\n";
echo "ORG:" . $user['Profile']['company'] . "\n";
echo "TITLE:" . $user['Profile']['function'] . "\n";
echo "ADR;TYPE=WORK:;;" . $user['Profile']['address'] . ";" . $user['Profile']['city'] . ";;" . $user['Profile']['zip'] . ";" . $user['Profile']['country'] . "\n";
echo "TEL;TYPE=WORK,VOICE:" . $user['Profile']['phone'] . "\n";
echo "EMAIL;TYPE=PREF,INTERNET:" . $user['User']['email']  . "\n";
echo "URL: " . Configure::read('CFG.site_url') . "/users/view/" . $user['User']['id'] . "\n";

$image = Configure::read('CFG.site_url') . $user['Profile']['photo'];
$image = str_replace(" ", "%20", $image);
$imagetypes = array (
    IMAGETYPE_JPEG => 'JPEG',
    IMAGETYPE_GIF  => 'GIF',
    IMAGETYPE_PNG  => 'PNG'
);

if ($imageinfo = @getimagesize($image) AND isset($imagetypes[$imageinfo[2]])) {
    $photo = base64_encode(file_get_contents($image));
    $type  = $imagetypes[$imageinfo[2]];
}

$vcard_photo = '';
if (isset($type, $photo)) {
    $vcard_photo .= sprintf("PHOTO;TYPE=$type;ENCODING=BASE64:");
}

$i=0;
$strphoto=sprintf($photo);

while ($i<strlen($strphoto)) {
    if ($i%75==0) {
        $vcard_photo .= "\r\n " . $strphoto[$i];
    } else {
        $vcard_photo .= $strphoto[$i];
    }
    $i++;
} 

echo $vcard_photo . "\n";
echo "REV:" . date('c') . "\n";
echo "END:VCARD\n";
?>