-
Notifications
You must be signed in to change notification settings - Fork 1
/
middleware-organizer-avatar-upload.php
42 lines (27 loc) · 1.17 KB
/
middleware-organizer-avatar-upload.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
<?php
require_once "./app/core/Handle.php";
require_once "./app/models/Organizer.php";
session_start();
Handle::authentication("account", Popups::mustBeAuthenticated(), "login.php");
Handle::requiredParameters([$_FILES['avatar']], Popups::requiredField(), "settings-organizer.php");
$organizer = $_SESSION['organizer'];
$accountID = $organizer->account_id;
$info = pathinfo($_FILES['avatar']['name']);
$extension = $info['extension'];
$newName = "organizer-" . $organizer->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/organizer/avatar/' . $newName;
Organizer::updateAvatar($accountID, $target);
$_SESSION['organizer'] = Organizer::getOrganizer($accountID);
if(file_exists($target))
unlink($target);
move_uploaded_file( $_FILES['avatar']['tmp_name'], $target);
Handle::setPopup(Popups::imageUploadSuccess());
Handle::redirect("settings-organizer.php");
}
?>