-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmiddleware-media-upload.php
43 lines (29 loc) · 1.17 KB
/
middleware-media-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
43
<?php
session_start();
require_once "./app/core/Handle.php";
require_once "./app/models/Media.php";
function uploadPhoto($image, $partyID, $number) {
$info = pathinfo($image['name']);
$extension = $info['extension'];
$newName = "artist-" . $partyID . "-" . $number ."." .$extension;
$target = './public/images/uploaded/party/album/' . $newName;
$isValid = getimagesize($image["tmp_name"]);
if ($image["size"] > 100000000)
Handle::setPopup(Popups::imageToLarge());
else if(($extension != "jpg" && $extension != "png") || !$isValid)
Handle::setPopup(Popups::wrongFileType());
else {
move_uploaded_file($image['tmp_name'], $target);
}
return $target;
}
Handle::hasManageAuthority();
Handle::authentication("organizer", Popups::mustBeAuthenticated(), "login.php");
Handle::requiredParameters([$_FILES['media']], Popups::requiredField(), "media.php");
$partyID = $_SESSION['party-manager']->party_id;
$number = Media::getNumberOfPhotos($partyID)->count;
$path = uploadPhoto($_FILES['media'], $partyID, $number);
Media::addPhoto($partyID, $path);
Handle::setPopup(Popups::photoAdded());
Handle::redirect("media.php");
?>