-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlepost.php
More file actions
78 lines (57 loc) · 2.38 KB
/
Copy pathhandlepost.php
File metadata and controls
78 lines (57 loc) · 2.38 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
<?php
require 'partials/_dbconnect.php';
$pic_uploaded = 0;
if(isset($_REQUEST["submit"]))
{
$thread_title = $_REQUEST['post-title'];
$thread_desc = $_REQUEST['post-description'];
$thread_cat_name = $_REQUEST['selected-cat'];
$thread_user_id = $_REQUEST['uid'];
$thread_title = str_replace("<", "<", $thread_title);
$thread_title = str_replace(">", ">", $thread_title);
$thread_title = str_replace("'", "'", $thread_title);
$thread_desc = str_replace("<", "<", $thread_desc);
$thread_desc = str_replace(">", ">", $thread_desc);
$thread_desc = str_replace("'", "'", $thread_desc);
$sql = "SELECT category_id FROM `categories` WHERE category_name = '$thread_cat_name'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$thread_cat_id = $row['category_id'];
$image = time().$_FILES["pic"]['name'];
if(move_uploaded_file($_FILES['pic']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/FP/img/'.$image))
{
$target_file = $_SERVER['DOCUMENT_ROOT'].'/FP/img/'.$image;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
$picname = basename($_FILES['pic']['name']);
$photo = time().$picname;
if($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png")
{
echo '<script>alert("Please post image having jpg/jpeg/png type");</script>';
}
else if($_FILES["pic"]["size"] > 20000000)
{
echo '<script>alert("Your Image size is too high");</script>';
}
else
{
$pic_uploaded = 1;
}
}
if($pic_uploaded == 1)
{
$insert_query = mysqli_query($conn, "INSERT INTO `threads` (`thread_title`, `thread_desc`, `thread_img`, `thread_cat_id`, `thread_user_id`, `timestamp`, `thread_likes`, `thread_dislike`) VALUES ('$thread_title','$thread_desc', '$photo', '$thread_cat_id', '$thread_user_id', current_timestamp(), '0', '0')");
if($insert_query > 0)
{
echo '
<script>
alert("New post added");
window.location = "index.php";
</script>';
}
}
else
{
echo '<script>alert("Failed to post");</script>';
}
}
?>