This repository has been archived by the owner on Nov 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaximg.php
95 lines (83 loc) · 3.03 KB
/
ajaximg.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
include __DIR__.'/configs/config.php';
include __DIR__.'/configs/class.upload.php';
$id = (int)($_POST['id']);
$photo = sc_sec($_POST['photo']);
$poll_imgurl = '';
if(!file_exists($_FILES['poll_file']['tmp_name']) || !is_uploaded_file($_FILES['poll_file']['tmp_name'])) {
//echo 'No upload';
} else {
$dir_dest = 'uploads';
$handle = new Upload($_FILES['poll_file']);
if ($handle->uploaded) {
$handle->file_safe_name = true;
$fileNewName = base64_encode($handle->file_src_name_body)."_".time();
$handle->file_new_name_body = $fileNewName;
$handle->Process($dir_dest);
if ($handle->processed) {
$poll_imgurl = $dir_dest.'/' . $handle->file_dst_name;
} else {
$alert = ["type" => "danger", "msg" => fh_alerts('File not uploaded to the wanted location<br />Error: ' . $handle->error)];
}
$handle->Clean();
} else {
$alert = ["type" => "danger", "msg" => fh_alerts('File not uploaded on the server<br />Error: ' . $handle->error)];
}
}
$photo = ($poll_imgurl) ? $poll_imgurl : $photo;
$data = [];
$fields = array('name', 'label_id', 'photo', 'bio');
// "lastname" => "'".sc_sec($_POST['lastname'])."'",
//"birthday" => "'".sc_sec($_POST['birthday'])."'",
//"birthmonth" => "'".sc_sec($_POST['birthmonth'])."'",
//"birthyear" => "'".sc_sec($_POST['birthyear'])."'",
// "deathday" => "'".sc_sec($_POST['deathday'])."'",
// "deathmonth" => "'".sc_sec($_POST['deathmonth'])."'",
// "deathyear" => "'".sc_sec($_POST['deathyear'])."'",
// "type" => "'".(int)($_POST['type'])."'",
// "death" => "'".(int)($_POST['death'])."'",
// "email" => "'".sc_sec($_POST['email'])."'",
// "site" => "'".sc_sec($_POST['site'])."'",
// "tel" => "'".sc_sec($_POST['tel'])."'",
// "mobile" => "'".sc_sec($_POST['mobile'])."'",
// "birthplace" => "'".sc_sec($_POST['birthplace'])."'",
// "deathplace" => "'".sc_sec($_POST['deathplace'])."'",
// "profession" => "'".sc_sec($_POST['profession'])."'",
// "company" => "'".sc_sec($_POST['company'])."'",
// "interests" => "'".sc_sec($_POST['interests'])."'",
foreach ($fields as $field) {
if ($field == 'photo') {
$data[$field] = "'$photo'";
} else {
$data[$field] = "'".sc_sec($_POST[$field])."'";
}
}
// date
if (isset($_POST['birthyear']) && $_POST['birthyear'] > 1900) {
$time = mktime(0, 0, 0, (int)$_POST['birthmonth'], (int)$_POST['birthday'], (int)$_POST['birthyear']);
$timestamp = date("Y-m-d H:i:s", $time);
if (preg_match('/^\d{4}\-\d{2}\-\d{2} /', $timestamp)) {
$data['date'] = "'".$timestamp."'";
}
else {
echo json_encode(['error' => 'Date, '.$timestamp.', is invalid', 'status' => 'error']);
exit;
}
}
if($id){
try {
db_update('bubbles', $data, $id);
} catch (Exception $e) {
error_log( 'Mysql error: '.$e->getMessage() );
}
} else {
$data["parent"] = "'".(int)($_POST['parent'])."'";
$data["family"] = "'".db_get('bubbles', 'family', (int)($_POST['parent']))."'";
try {
db_insert('bubbles', $data);
} catch (Exception $e) {
error_log( 'Mysql error: '.$e->getMessage() );
}
}
// echo json_encode($array_msg);
// echo $photo;