-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_vcard.php
56 lines (50 loc) · 1.89 KB
/
upload_vcard.php
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
47
48
49
50
51
52
53
54
55
56
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$telephoneProfessionnel = $_POST['telephone-professionnel'];
$email = $_POST['email'];
$website = $_POST['website'];
$adresse = $_POST['adresse'];
$whatsapp = $_POST['whatsapp'];
$vcard = "BEGIN:VCARD\nVERSION:3.0\n";
$vcard .= "N:$nom;$prenom;;;\n";
$vcard .= "FN:$prenom $nom\n";
if ($telephoneProfessionnel) $vcard .= "TEL;TYPE=WORK:$telephoneProfessionnel\n";
$vcard .= "EMAIL:$email\n";
if ($website) $vcard .= "URL:$website\n";
if ($adresse) $vcard .= "ADR:;;$adresse;;;;\n";
if ($whatsapp) $vcard .= "TEL;TYPE=WHATSAPP:$whatsapp\n";
$photoData = '';
if (isset($_FILES['photo']) && $_FILES['photo']['error'] == 0) {
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$photoPath = $uploadDir . basename($_FILES['photo']['name']);
if (move_uploaded_file($_FILES['photo']['tmp_name'], $photoPath)) {
$photoData = base64_encode(file_get_contents($photoPath));
$vcard .= "PHOTO;ENCODING=BASE64;TYPE=JPEG:$photoData\n";
}
}
if (isset($_POST['social-platform']) && isset($_POST['social-url'])) {
$socialPlatforms = $_POST['social-platform'];
$socialUrls = $_POST['social-url'];
foreach ($socialPlatforms as $index => $platform) {
$url = $socialUrls[$index];
if ($url) {
$vcard .= "X-SOCIALPROFILE;TYPE=$platform:$url\n";
}
}
}
$vcard .= "END:VCARD";
$filename = $uploadDir . uniqid() . '.vcf';
if (file_put_contents($filename, $vcard)) {
echo json_encode(['success' => true, 'url' => $filename]);
} else {
echo json_encode(['success' => false]);
}
}
?>