forked from skol-1/medical-imaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
79 lines (53 loc) · 1.7 KB
/
helper.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
<?php
function validate_input_text($textValue){
if (!empty($textValue)){
$trim_text = trim($textValue);
// remove illegal character
$sanitize_str = filter_var($trim_text, FILTER_SANITIZE_STRING);
return $sanitize_str;
}
return '';
}
function validate_input_email($emailValue){
if (!empty($emailValue)){
$trim_text = trim($emailValue);
// remove illegal character
$sanitize_str = filter_var($trim_text, FILTER_SANITIZE_EMAIL);
return $sanitize_str;
}
return '';
}
// profile image
function upload_profile($path, $file){
$targetDir = $path;
$default = "beard.png";
// get the filename
$filename = basename($file['name']);
$targetFilePath = $targetDir . $filename;
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
If(!empty($filename)){
// allow certain file format
$allowType = array('jpg', 'png', 'jpeg', 'gif', 'pdf');
if(in_array($fileType, $allowType)){
// upload file to the server
if(move_uploaded_file($file['tmp_name'], $targetFilePath)){
return $targetFilePath;
}
}
}
// return default image
return $path . $default;
}
// get user info
function get_user_info($con, $userID){
$query = "SELECT firstName, lastName, email, profileImage FROM user WHERE userID=?";
$q = mysqli_stmt_init($con);
mysqli_stmt_prepare($q, $query);
// bind the statement
mysqli_stmt_bind_param($q, 'i', $userID);
// execute sql statement
mysqli_stmt_execute($q);
$result = mysqli_stmt_get_result($q);
$row = mysqli_fetch_array($result);
return empty($row) ? false : $row;
}