-
Notifications
You must be signed in to change notification settings - Fork 3
/
posting-img.php
85 lines (54 loc) · 1.64 KB
/
posting-img.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
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
<?php
session_start();
if(!isset($_SESSION['id']))
{
header('location: login.php');
exit;
}
include('config.php');
if(isset($_POST['posting']))
{
$filename = $_FILES['image']['name'];
$tempname = $_FILES["image"]["tmp_name"];
$file_extansion = pathinfo($filename, PATHINFO_EXTENSION);
$random_number = rand(0, 10000000);
$file_rename = 'File_'.date('Ymd').$random_number;
$file_complete = $file_rename.'.'.$file_extansion;
$ID = $_SESSION['id'];
$caption = $_POST['caption'];
$hashtags= $_POST['hash-tags'];
$folder = "./assets/images/posts/" . $file_complete;
$likes = 0;
$date = date("Y-m-d H:i:s");
$sql_query = "INSERT INTO Posts (User_ID, Likes, Img_Path, Caption, HashTags, Date_Upload) VALUES
($ID, $likes, '$file_complete','$caption', '$hashtags','$date')";
echo $sql_query;
$stmt = $conn->prepare($sql_query);
if($stmt->execute())
{
move_uploaded_file($tempname, $folder);
header("location: post-uploader.php?success_message=Post Successfully updated");
update_Posts($ID);
exit;
}
else
{
header("location: post-uploader.php?error_message=Error Occurred, try again - ERROR #008");
exit;
}
}
else
{
header("location: post-uploader.php?error_message=Error Occurred, try again2 - ERROR #009");
exit;
}
function update_Posts($user_id)
{
include 'config.php';
$insert_query = "UPDATE users SET POSTS = POSTS+1 WHERE User_ID = $user_id ;";
$stmt = $conn->prepare($insert_query);
if ($stmt->execute()) {
$_SESSION['postcount'] = $_SESSION['postcount']+1;
}
}
?>