-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddPost.php
More file actions
92 lines (83 loc) · 2.6 KB
/
addPost.php
File metadata and controls
92 lines (83 loc) · 2.6 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
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
include 'dbconn.php';
connect();
$post_time = (string)(microtime(true))*10000;
echo $post_time."<br>";
$curr_date_time = date("Y-m-d H:i:s");
$u_id=$_SESSION['user_id'];
$viewershipphp='friends';
$contents = $_POST['postcontent'];
if(trim($contents)!=''){
header("Location: index.php");
$stmt = $conn->prepare("INSERT INTO POST (POST_ID,USER_ID, ADD_DATE,CONTENT,VIEWERSHIP) VALUES(?, ?, ?, ?, ?)");
$stmt->bind_param("iisss",
$post_time,
$u_id,
$curr_date_time,
$contents,
$viewershipphp);
if ($stmt->execute() === TRUE) {
echo "New Post added<br>";
} else {
echo "Error<br>" . $conn->error;
}
}
// Upload Photos
echo isset($_FILES['uploaded']['tmp_name']);
echo "<br>";
if(isset($_FILES['uploaded']['tmp_name'][0])){
echo count($_FILES['uploaded']['tmp_name'][0]).'<br>';
for($i = 0; $i < count($_FILES['uploaded']['tmp_name']); $i++){
$target = "photos/";
$t_stamp = (string)(microtime(true))*10000;
$f_name = $t_stamp .'.'. end(explode(".", $_FILES['uploaded']['name'][$i]));
$target = $target . $f_name;
$uploaded_size = $_FILES['uploaded']['size'][$i];
$ok=1;
//This is our size condition
if ($uploaded_size > 2097152*16){
echo "Your file is too large. We have a 32MB limit.<br>";
$ok=0;
}
$types = array('image/jpeg', 'image/gif', 'image/png');
if (in_array($_FILES['uploaded']['type'][$i], $types)) {
// file is okay continue
} else {
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0){
Echo "Sorry your file was not uploaded. It may be the wrong filetype. We only allow JPG, GIF, and PNG filetypes.";
}
//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'][$i], $target)){
connect();
$sql="INSERT INTO PHOTOS(PHOTO_ID,POST_ID,USER_ID,ADD_DATE,LINK,VIEWERSHIP) VALUES (".
$t_stamp.",".
$post_time.",".
$u_id.",'".
date("Y-m-d H:i:s")."','".
$f_name."','".
$viewershipphp."');";
if ($conn->query($sql) === TRUE) {
echo "New Photo added";
// header('Location: index.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
disconnect();
echo "The file ". basename( $_FILES['uploaded']['name'][$i]). " has been uploaded";
}
else{
echo "Sorry, there was a problem uploading your file.";
}
}
}
}
disconnect();
header("Location: index.php");
?>