-
Notifications
You must be signed in to change notification settings - Fork 1
/
middleware-avatar-setup.php
35 lines (24 loc) · 1.07 KB
/
middleware-avatar-setup.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
<?php
require_once "./app/core/Handle.php";
require_once "./app/models/Accounts.php";
session_start();
Handle::authentication("account", Popups::mustBeAuthenticated(), "login.php");
Handle::requiredParameters([$_FILES['avatar']], Popups::requiredField(), "avatar-setup.php");
$account = $_SESSION['account'];
$info = pathinfo($_FILES['avatar']['name']);
$extension = $info['extension'];
$newName = "avatar-" . $account->account_id . "." .$extension;
$isValid = getimagesize($_FILES["avatar"]["tmp_name"]);
if ($_FILES["avatar"]["size"] > 100000000)
Handle::setPopup(Popups::imageToLarge());
else if(($extension != "jpg" && $extension != "png") || !$isValid)
Handle::setPopup(Popups::wrongFileType());
else {
$target = './public/images/uploaded/account/' . $newName;
move_uploaded_file( $_FILES['avatar']['tmp_name'], $target);
Accounts::updateAvatar($target, $account->account_id);
Accounts::updateSetupProcess($account->account_id, 'FINISHED');
$_SESSION['account'] = Accounts::getAccountViaID($account->account_id);
}
Handle::redirect("register.php");
?>