-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.php
81 lines (69 loc) · 2.43 KB
/
info.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
<?php
require 'core/base.php';
$target_file = '';
if (isset($_POST['poll']) && !empty($_POST['poll'])) {
$poll = $_POST['poll'];
//poll image upload to server
if(isset($_FILES["pollfile"]) && !empty($_FILES["pollfile"]["tmp_name"])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["pollfile"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["pollfile"]["tmp_name"]);
if($check !== false || $_FILES["fileToUpload"]["size"] < 100000) {
move_uploaded_file($_FILES["pollfile"]["tmp_name"], $target_file);
echo "File is an image - " . $check["mime"] . ".";
} else {
echo "File is not an image or maybe your file size is too large";
}
}
}else{
header("Location: poll.php?error=Poll question field is empty");
exit();
}
if(isset($_POST['ip']) && $_POST['ip']==='accepted'){
$ip = 'yes';
}else{
$ip = 'no';
}
if(isset($_POST['private']) && $_POST['private']==='accepted'){
$private = 'yes';
}else{
$private = 'no';
}
if (isset($_POST['message'])){
$msg = $_POST['message'];
}
$options = $_POST['options'];
if(count(array_filter($options)) < 2 ){
header("Location: poll.php?error=you must have to fill two options 😢");
exit();
}
$vote = array();
for ($i = 0; $i < count(array_filter($options)); $i++)
{
array_push($vote, 0);
}
//check option images if user uploaded
if(isset($_FILES['opttionfile'])){
$optionimg = array();
foreach($_FILES['opttionfile']['tmp_name'] as $key => $tmp_name)
{
$file_name = $key.$_FILES['opttionfile']['name'][$key];
$opt_dir = "uploads/".time().$file_name;
// $file_size =$_FILES['documents']['size'][$key];
$file_tmp =$_FILES['opttionfile']['tmp_name'][$key];
// $file_type=$_FILES['documents']['type'][$key];
move_uploaded_file($file_tmp,$opt_dir);
array_push($optionimg, $opt_dir);
}
}
// echo $ip;
// echo get_ip_address();
$database->insert("question", [ "poll" => $poll, "img" => $target_file, "description" => $msg, "options" => array_filter($options), "options_img" => $optionimg, "vote" => $vote, "time" => time() ]);
$poll_id = $database->id();
$database->insert("setting", [ "poll_id" => $poll_id, "ip" => $ip, "private" => $private ]);
if(!empty($poll_id)){
header("Location: vote.php?id=$poll_id");
}
?>