Repository navigation
Expand file tree
/
Copy pathpost.php
More file actions
122 lines (97 loc) · 3.52 KB
/
Copy pathpost.php
File metadata and controls
122 lines (97 loc) · 3.52 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
//Check isset for the button
session_start();
//Checking for session
$loggedIn = isset($_SESSION['loggedIn']) ? $_SESSION['loggedIn'] : false;
if ($loggedIn == false){
header("Location: index.php");
exit();
}
//Require database connection
require "files/dbconfig.php";
$con = new DBConfig();
//Require class user to get user details
require "files/user.php";
$user = new User();
//Require classs to get post data
require "files/posts.php";
$post = new Posts();
//Including categories files
include "files/categories.php";
$categoryObj = new Categories();
//Require the functions page
require "includes/functions.php";
if ($loggedIn == true){
$userlvl = $user->userLevel($_SESSION['uid']);
$permission = $user->userPermissions($userlvl);
$canPost = $permission['post'];
if ($canPost == 1){
//Initialising varables
$uid = $_SESSION['uid'];
$title = validData($_POST['p-title']);
$category = validData($_POST['p-cat']);
$body = trim($_POST['p-body']);
$allowCom = isset($_POST['p-com']) ? validData($_POST['p-com']) : 'yes';
$banner = isset($_FILES['p-banner']) ? $_FILES['p-banner'] : false;
//variable to check whether banner uploaded or not
$fileOK = 0;
//Validating the data
if (strlen($title)<10){
echo "Title must have at least 10 charachters";
exit();
}elseif (strlen($body)<50){
echo "Body must contain at least 50 charachters";
exit();
}
//Checking for valid category
$categoryExist = $categoryObj->categoryName($category);
if ($categoryExist == -1){
echo 'No such category available';
exit();
}
//Uplooading banner
if ($banner != false){
$bannerName = $_FILES['p-banner']['name'];
$tmpLocation = $_FILES['p-banner']['tmp_name'];
$bannerSize = $_FILES['p-banner']['size'];
$bannerError = $_FILES['p-banner']['error'];
$bExt = explode('.', $bannerName);
$bActExt = strtolower(end($bExt));
$permitted = array('jpg', 'jpeg', 'png', 'gif');
if (in_array($bActExt, $permitted)){
if ($bannerError === 0){
if ($bannerSize < 1000000){
$bNewName = uniqid('', true).".".$bActExt;
$destination = 'banners/'.$bNewName;
move_uploaded_file($tmpLocation, $destination);
//The banner was uploaded sucessfully
$fileOK = 1;
}
else {
echo "Max image size allowed is 1 MB";
}
}
else {
echo "There was an error uploading the image";
}
}
else{
echo "File type not allowed";
}
}
//Uploading data in database
if ($fileOK == 1){
//setting date
date_default_timezone_set("Asia/Calcutta");
$date = date("Y-m-d H:i:s");
//Setting up the SEO URL
$slug = slugify($title);
$id = $post->addPost($uid, $category, $title, $date, $bNewName, $body, $allowCom, $slug);
header("Location: view-post.php?pid=".$id);
} else {
echo 'There was an error uploading the banner.';
}
}
} else {
echo 'You are not logged in';
}