Bonjour,
Je crée une classe de création de vCard. Je vous mets les fonctions de sortie ci-dessous.
La méthode __toString() fonctionne très bien, par contre si j'essaye la méthode download(), j'obtiens le résultat suivant et je n'arrive pas à ouvrir le fichier généré:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public function download() { // define output $output = $this->getOutput(); foreach ($this->getHeaders() as $header) { header($header); } // echo the output and it will be a download echo $output; } public function getOutput() { $vCard = <<<VCF BEGIN:VCARD VERSION:4.0 %s END:VCARD VCF; $content = []; foreach ($this->properties as $name=>$value) { $content[] = "$name:$value"; } return sprintf($vCard, implode("\r\n", $content)); } public function getHeaders() { var_dump(__method__); $contentType = 'Content-type: text/vcard; charset=utf-8'; //$contentDisposition = 'attachment; filename=' . $this->getFilename() . '.' . $this->getFileExtension(); $contentDisposition = 'attachment; filename=' . $this->properties['FN'] . '.vcf'; // A améliorer selon exemple ci-dessus $contentLength = mb_strlen($this->getOutput(), '8bit'); $connection = 'close'; return [ 'Content-type: ' . $contentType, 'Content-Disposition: ' . $contentDisposition, 'Content-Length: ' . $contentLength, 'Connection: ' . $connection, ]; } public function __toString() { // A des fins de contrôle essentiellement return $this->getOutput(); }P.S. Je ne sais pas ce que j'ai fait mais maintenant je n'ai plus aucune sortie.<pre class='xdebug-var-dump' dir='ltr'>
<small>C:\wamp64\www\hotels\classes\moimp\vCard.php:327:</small><small>string</small> <font color='#cc0000'>'VCard\VCard::getHeaders'</font> <i>(length=23)</i>
</pre>BEGIN:VCARD
VERSION:4.0
FN:Toto
ADR;PREF=1:;;Bielstraße 5;Lengnau;Aargau;2543;CH
TEL;VALUE=uri;PREF=1;TYPE="voice":tel:+41-32-652-0000
TEL;VALUE=uri;PREF=2;TYPE="fax":tel:+41-32-652-0000
LANG;PREF=1:de
END:VCARDBEGIN:VCARD<br />
VERSION:4.0<br />
FN:Toto<br />
ADR;PREF=1:;;Bielstraße 5;Lengnau;Aargau;2543;CH<br />
TEL;VALUE=uri;PREF=1;TYPE="voice":tel:+41-32-652-0000<br />
TEL;VALUE=uri;PREF=2;TYPE="fax":tel:+41-32-652-0000<br />
LANG;PREF=1:de<br />
END:VCARD
Partager