vcard profile image not show on mobile php script

90 Views Asked by At

I create a vcard export system with php. this is code

function generate_vcard($post_id) {
    // Get ACF field values for the post
    $title = get_field('title', $post_id);
    $first_name = get_field('first_name', $post_id);
    $last_name = get_field('last_name', $post_id);
    $position = get_field('position', $post_id);
    $company = get_field('company', $post_id);
    $birthday = get_field('birthday', $post_id);
    $office_phone = get_field('office_phone', $post_id);
    $cell_phone = get_field('cell_phone', $post_id);
    $email_1 = get_field('email_1', $post_id);
    $email_2 = get_field('email_2', $post_id);
    $website = get_field('website', $post_id);
    
    // Get profile image URL from ACF field
    $profile_image = get_field('profile_image', $post_id);
    
    // Encode the image to base64
    $image_data = file_get_contents($profile_image);
    $base64_image = base64_encode($image_data);
    
    // Generate vCard content
    $vcard = "BEGIN:VCARD\n";
    $vcard .= "VERSION:3.0\n";
    $vcard .= "FN:$first_name $last_name\n";
    $vcard .= "N:$last_name;$first_name;;;\n";
    $vcard .= "ORG:$company\n";
    $vcard .= "TITLE:$position\n";
    $vcard .= "BDAY:$birthday\n";
    $vcard .= "TEL;TYPE=WORK,VOICE:$office_phone\n";
    $vcard .= "TEL;TYPE=CELL,VOICE:$cell_phone\n";
    $vcard .= "EMAIL:$email_1\n";
    $vcard .= "EMAIL:$email_2\n";
    $vcard .= "URL:$website\n";
    $vcard .= "PHOTO;TYPE=JPEG;ENCODING=b;VALUE=URL:$base64_image\n";
    $vcard .= "END:VCARD\n";

    // Set headers to trigger download
    header("Content-Type: text/vcard");
    header("Content-Disposition: attachment; filename=contact.vcf");

    // Output vCard content
    echo $vcard;
    exit;
}

Everything works find just the user profile picture does not show on mobile but in pc it works. The info come from ACF of custom post type. What should I do to solve it?

0

There are 0 best solutions below