-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard_insert.php
102 lines (83 loc) ยท 2.69 KB
/
board_insert.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<meta charset="utf-8">
<?php
session_start();
if (isset($_SESSION["userid"])) $userid = $_SESSION["userid"];
else $userid = "";
if (isset($_SESSION["username"])) $username = $_SESSION["username"];
else $username = "";
if ( !$userid )
{
echo("
<script>
alert('๊ฒ์ํ ๊ธ์ฐ๊ธฐ๋ ๋ก๊ทธ์ธ ํ ์ด์ฉํด ์ฃผ์ธ์!');
history.go(-1)
</script>
");
exit;
}
$subject = $_POST["subject"];
$content = $_POST["content"];
$subject = htmlspecialchars($subject, ENT_QUOTES);
$content = htmlspecialchars($content, ENT_QUOTES);
$regist_day = date("Y-m-d (H:i)"); // ํ์ฌ์ '๋
-์-์ผ-์-๋ถ'์ ์ ์ฅ
$upload_dir = './data/';
$upfile_name = $_FILES["upfile"]["name"];
$upfile_tmp_name = $_FILES["upfile"]["tmp_name"];
$upfile_type = $_FILES["upfile"]["type"];
$upfile_size = $_FILES["upfile"]["size"];
$upfile_error = $_FILES["upfile"]["error"];
if ($upfile_name && !$upfile_error)
{
$file = explode(".", $upfile_name);
$file_name = $file[0];
$file_ext = $file[1];
$new_file_name = date("Y_m_d_H_i_s");
$new_file_name = $new_file_name;
$copied_file_name = $new_file_name.".".$file_ext;
$uploaded_file = $upload_dir.$copied_file_name;
if( $upfile_size > 1000000 ) {
echo("
<script>
alert('์
๋ก๋ ํ์ผ ํฌ๊ธฐ๊ฐ ์ง์ ๋ ์ฉ๋(1MB)์ ์ด๊ณผํฉ๋๋ค!<br>ํ์ผ ํฌ๊ธฐ๋ฅผ ์ฒดํฌํด์ฃผ์ธ์! ');
history.go(-1)
</script>
");
exit;
}
if (!move_uploaded_file($upfile_tmp_name, $uploaded_file) )
{
echo("
<script>
alert('ํ์ผ์ ์ง์ ํ ๋๋ ํ ๋ฆฌ์ ๋ณต์ฌํ๋๋ฐ ์คํจํ์ต๋๋ค.');
history.go(-1)
</script>
");
exit;
}
}
else
{
$upfile_name = "";
$upfile_type = "";
$copied_file_name = "";
}
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "insert into board (id, name, subject, content, regist_day, hit, file_name, file_type, file_copied) ";
$sql .= "values('$userid', '$username', '$subject', '$content', '$regist_day', 0, ";
$sql .= "'$upfile_name', '$upfile_type', '$copied_file_name')";
mysqli_query($con, $sql); // $sql ์ ์ ์ฅ๋ ๋ช
๋ น ์คํ
// ํฌ์ธํธ ๋ถ์ฌํ๊ธฐ
$point_up = 100;
$sql = "select point from members where id='$userid'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
$new_point = $row["point"] + $point_up;
$sql = "update members set point=$new_point where id='$userid'";
mysqli_query($con, $sql);
mysqli_close($con); // DB ์ฐ๊ฒฐ ๋๊ธฐ
echo "
<script>
location.href = 'board_list.php';
</script>
";
?>