-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
executable file
·43 lines (38 loc) · 949 Bytes
/
ajax.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
require('Db.php');
require('FileUtil.php');
//Remove movie
if(isset($_POST['remove'])) {
$id = intval(trim($_POST['id']));
if(Db::removeMovie($id)) {
$files = glob('./movies/movie'.$id.'.*');
unlink($files[0]);
header("HTTP/1.1 200 OK");
echo 'Successfull removal...';
} else {
header("HTTP/1.1 400 Bad Request");
echo 'Uh Oh..';
}
}
//Submit movie
if(isset($_POST['submit'])) {
$title = trim($_POST['movie-title']);
$desc = trim($_POST['movie-desc']);
$rating = intval($_POST['movie-rating']);
$id = Db::addMovie($title,$desc,$rating);
if($id){
$file = $_FILES['poster'];
$file['id'] = $id;
if(FileUtil::saveImage($file)) {
header("HTTP/1.1 201 Created");
echo $id;
} else {
header('HTTP/1.1 400 Bad Request');
echo 'File not Please try a different file...';
}
} else {
header("HTTP/1.1 500 Server error");
echo 'Could not save movie...';
}
}
?>