Open hariom-darkbears opened 5 years ago
Are you using $vcard->download()
or $vcard->getOutput()
? If you are using getOutput()
you will need to add the appropriate headers to your response. My guess is that the response are returning something like text/html
instead of text/vcard
and then iphone will not open it as a contact file.
Are you using
$vcard->download()
or$vcard->getOutput()
? If you are usinggetOutput()
you will need to add the appropriate headers to your response. My guess is that the response are returning something liketext/html
instead oftext/vcard
and then iphone will not open it as a contact file.
Hey @nettum Yes response are returning like 'text/html'.. could you please help me to write down appropriate headers...
Well, this package already have a function to get the appropriate headers so you could do
foreach ($vcard->getHeaders(false) as $header) {
header($header);
}
to get all the headers you need and set them. But then you could just use $vcard->download();
instead. In that case you do not need to to set the headers yourself as the library does it for you.
If you still want to do it manually you could use header('Content-Type: text/vcard');
i'm facing the same download issue on iphone but case is little different. normally if i visit a site and click download button on iphone it works download a contact file. but if click a website link from instagram or facebook app, you know they opens links using in-app browsers. then i click on download button and it shows the string output. but works fine for android.
i did check the function isIOS() it gives TRUE . i do not know what is error. can anyone fix it ?
@hariom-darkbears did you solve the issue ?
@itsmemanoj Im using $vcard->download ad still doing it. the weird thing is that only are some users, not all.
Update:
The photo is required? that was my problem.
@miguelcalderons downloading vCard is working fine for me too but only on known browsers like firefox, safari, chrome. But when I click the download link from the Instagram or facebook Bio ( using their App ). Then you know, they open links using in-app browsers, those browsers are just displaying output string not downloading the file.
Best solution for iphone is replace $vcard->download();
with following:
$response = new Response();
$response->setContent($vcard->getOutput());
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'text/x-vcard');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $name_here . '.vcf"');
$response->headers->set('Content-Length', mb_strlen($vcard->getOutput(), 'utf-8'));
return $response;
Best solution for iphone is replace
$vcard->download();
with following:
$response = new Response();
$response->setContent($vcard->getOutput());
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'text/x-vcard');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $name_here . '.vcf"');
$response->headers->set('Content-Length', mb_strlen($vcard->getOutput(), 'utf-8'));
return $response;
This is working well for me on android phones, however on iOS nothing is happening. Any idea how to fix this? I also tried
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$response->setContent($content);
$response->setStatusCode(200);
if( $iPhone ){
$response->headers->set('Content-Type', 'text/vcard');
}else{
$response->headers->set('Content-Type', 'text/x-vcard');
}
$response->headers->set('Content-Disposition', 'attachment; filename="'.'contact'.'.vcf"');
$response->headers->set('Content-Length', mb_strlen($content, 'utf-8'));
return $response;
but it still does not work on iPhone, nothing happens
@ElifBahar did you sovled this ??
@aviqa1984 yes but i had to write down the code manually on my controller. I searched online and combined couple of things i found.. Here is how i did it:
`
public function exportVCF($url){
//Retrieve the user you want to make a card of
$user = User::where('url',$url)->first();
//Create card
$content2 = "BEGIN:VCARD\r\n";
$content2 .= "VERSION:3.0\r\n";
$content2 .= "CLASS:PUBLIC\r\n";
$content2 .= "FN:".$user->name."\r\n";
$content2 .= "N:".$user->name."\r\n";
if($user->getCompany->count() > 0){
$company_info = $user->getCompany->first();
if($company_info->company_name != null){
$content2 .= "ORG:".$company_info->company_name."\r\n";
}if($company_info->title != null){
$content2 .= "TITLE:".$company_info->title."\r\n";
}if($company_info->work_mail != null){
$content2 .= "EMAIL;TYPE=internet,pref:".$company_info->work_mail."\r\n";
}if($company_info->work_phone != null){
$content2 .= "TEL;TYPE=work,voice:".$company_info->work_phone."\r\n";
}if($company_info->work_web_site != null){
$content2 .= "URL:".$company_info->work_web_site."\r\n";
}if($company_info->address != null){
$content2 .= "ADR;TYPE=work:".$company_info->address."\r\n";
}
}
$content2 .= "END:VCARD\r\n";
//Create a response
$response = new Response();
$response->setContent($content2);
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'text/vcard');
$response->headers->set('Content-Disposition', 'attachment; filename="'.'contact'.'.vcf"');
$response->headers->set('Content-Length', mb_strlen($content2, 'utf-8'));
return $response;
}
`
When i use this on Android, then it's working fine and download a file with .vcf extension.
But when i use this with Iphone then it's not working only show me as output string.(Not downloadable file).
Please quick help!