Repository navigation
Expand file tree
/
Copy pathcustomizeProf.php
More file actions
executable file
·75 lines (57 loc) · 2.32 KB
/
Copy pathcustomizeProf.php
File metadata and controls
executable file
·75 lines (57 loc) · 2.32 KB
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
<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$file = $_FILES["file"];
$fileName = $_FILES["file"]["name"];
$fileTmpName = $_FILES["file"]["tmp_name"];
$fileSize = $_FILES["file"]["size"];
$fileError = $_FILES["file"]["error"];
$fileType = $_FILES["file"]["type"];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$extAllowed = array('jpg', 'png', 'jpeg',);
try {
require_once "sessionconfig.inc.php";
require_once "dbconnection.inc.php";
require_once "signup_model.inc.php";
// ERROR HANDLING
$makosa = [];
if (!in_array($fileActualExt, $extAllowed)) {
$makosa["unsuportedformat"] = "Upload an image with format of either jpg, jpeg, png";
} else if ($fileError > 0) {
$makosa["unknownerror"] = "There was an error on uploading your file";
} else if ($fileSize > 50000000000) {
$makosa["bigsize"] = "Your image size is too big";
} else if (in_array($fileActualExt, $extAllowed) && $fileError === 0 && $fileSize < 5000000) {
$newFileName = uniqid("", true) . "." . $fileActualExt;
$fileDestination = 'assets/UserPics/' . $newFileName;
$_SESSION["fileDestination"] = $fileDestination;
move_uploaded_file($fileTmpName, $fileDestination);
if ($_SESSION["useremail"]) {
$email = $_SESSION["useremail"];
$profile_pic_id = $_SESSION["fileDestination"];
update_profile($unigram_conn, $email, $profile_pic_id);
http_response_code(200);
echo json_encode($success = "You have succeed in registering now use your credentials to login");
} else {
$makosa["uploadfailed"] = "Uploading your file failed try again";
}
}
if ($makosa) {
$_SESSION["makosa"] = $makosa;
if ($_SESSION["makosa"]) {
http_response_code(400);
echo json_encode($makosa);
}
exit();
}
unset($_SESSION["makosa"]);
$unigram_conn = null;
$stmt = null;
exit();
} catch (PDOException $e) {
die("connection error:" . $e->getMessage());
};
} else {
header("location: chat.php");
die();
}