-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatePost.php
More file actions
72 lines (65 loc) · 2.26 KB
/
createPost.php
File metadata and controls
72 lines (65 loc) · 2.26 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
<?php
session_start();
//initialisation of shit needed
require_once("Models/CategoryGetter.php");
$categoryGetter = new CategoryGetter();
require_once("Models/PostMaker.php");
//gets categories and put them in view
$view = new stdClass();
$view->categories = $categoryGetter->getAllCatNames();
if(isset($_POST['submit']))
{
$postMaker = new PostMaker(); //initialisation of needed class
//sanitising content
$_POST['title'] = htmlentities($_POST['title']);
//var_dump($_POST['title']);
$_POST['content'] = htmlentities($_POST['content']);
$_POST['titleCheck'] = $postMaker->checkTitle($_POST['title']);
$_POST['contentCheck'] = $postMaker->checkContent($_POST['content']);
//if(isset($_FILES['image']['error'])) //if an image is uploaded
if($_FILES['image']['error']!=4) //if user has uploaded an image
{
$_POST['imageCheck'] = $postMaker->checkImage($_FILES['image']);
//var_dump($_POST['imageCheck']);
}
else //if not
{
$_POST['imageCheck'] = true;
}
//var_dump($_FILES['image']);
if($_POST['imageCheck'] == true) //if file is an image
{
$_POST['sizeCheck'] = $postMaker->checkImageSize($_FILES['image']);
}
else
{
$_POST['sizeCheck'] = false;
}
if($_POST['imageCheck'] == true && $_POST['sizeCheck'] == true)
{
move_uploaded_file($_FILES['image']['tmp_name'],"images/".basename($_FILES['image']['name']));
}
//if all checks have passed
if($_POST['titleCheck'] == true && $_POST['contentCheck'] == true && $_POST['imageCheck'] == true && $_POST['sizeCheck'] == true)//if both checks passed
{
if($_POST['imageCheck'] == true && $_POST['sizeCheck'] == true) //if post has an image
{
//var_dump($_FILES);
$image = basename($_FILES['image']['name']);
$postMaker->commitImagePost($_SESSION['userID'], $_POST['category'], $_POST['title'], $_POST['content'],$image);
}
else
{
$postMaker->commitPost($_SESSION['userID'], $_POST['category'], $_POST['title'], $_POST['content']);
}
header("Location: /index.php");
}
}
if(isset($_SESSION['loggedIn']))
{
require_once("Views/createPost.phtml");
}
else
{
echo "ERROR: you shouldn't be here";
}