-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_write.php
104 lines (101 loc) Β· 4.07 KB
/
board_write.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
103
104
<?php
$mysql_host = "localhost";
$mysql_user = "hoppydream";
$mysql_passwd = "xTGRThJqGgFJ2fNh";
$mysql_db = "hoppydream";
$conn = mysqli_connect($mysql_host, $mysql_user, $mysql_passwd, $mysql_db);
if (!$conn) {
die("μ°κ²° μ€ν¨ : " . mysqli_connect_error());
}
mysqli_query ($conn, 'SET NAMES utf8');
?>
<script> console.log('μ°κ²°μ±κ³΅')</script>
<!--dbμ°κ²° --------------------------------------------
----------------------------------------------->
<?php
//$name1 = iconv("euc-kr","UTF-8",$name);
$get_loc = $_POST['loc']; //μ§μ
$uploads_dir = 'files';
$imgName = "img";
$get_score = $_POST["score"]; //λ³μ
$get_title = $_POST["title"]; //κ°κ²μ΄λ¦
$get_review = $_POST["review"]; //리뷰
$DBFile = "";
if (isset($_FILES[$imgName])) {
if (!is_dir($uploads_dir)) {
if (!mkdir($uploads_dir, 0777)) die("μ
λ‘λ λλ ν 리 μμ±μ μ€ν¨ νμ΅λλ€.");
echo "<script> console.log('μ
λ‘λ λλ ν 리 μμ±μ μ€ν¨')</script>";
}
$error = $_FILES[$imgName]['error'];
$name = $_FILES[$imgName]['name'];
// μ€λ₯ νμΈ
if ($error != UPLOAD_ERR_OK) {
switch ($error) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
echo "<script> alert('νμΌ μ©λμ΄ λ무 ν½λλ€.'); location.replace('bootdiv.php'); </script>";
break;
case UPLOAD_ERR_PARTIAL:
echo "<script> alert('νμΌμ΄ λΆλΆμ μΌλ‘ 첨λΆλμμ΅λλ€.'); location.replace('bootdiv.php'); </script>";
break;
case UPLOAD_ERR_NO_FILE:
echo "<script> alert('νμΌμ΄ 첨λΆλμ§ μμμ΅λλ€.'); location.replace('bootdiv.php'); </script>";
break;
case UPLOAD_ERR_NO_TMP_DIR:
echo "<script> alert('μμνμΌμ μ μ₯ν λλ ν λ¦¬κ° μμ΅λλ€.'); location.replace('bootdiv.php'); </script>";
break;
case UPLOAD_ERR_CANT_WRITE:
echo "<script> alert('μμνμΌμ μμ±ν μ μμ΅λλ€.'); location.replace('bootdiv.php'); </script>";
break;
case UPLOAD_ERR_EXTENSION:
echo "<script> alert('μ
λ‘λ λΆκ°λ₯ν νμΌμ
λλ€.'); location.replace('bootdiv.php'); </script>";
break;
default:
echo "<script> alert('νμΌμ΄ μ λλ‘ μ
λ‘λλμ§ μμμ΅λλ€.'); location.replace('bootdiv.php'); </script>";
}
exit;
}
$uploadFile = $uploads_dir . '/' . $name; // μ μ₯λ λλ ν 리 λ° νμΌλͺ
$fileNameWithoutExt = substr($name, 0, strrpos($name, ".")); //νμ₯μ λΊ νμΌμ΄λ¦
$file_ext = strtolower(substr(strrchr($name, "."), 1)); //νμ₯μ
$fileinfo = pathinfo($uploadFile); // 첨λΆνμΌμ μ 보λ₯Ό κ°μ Έμ΄
$i = 1;
$name = date("YmdHis").'.'.$file_ext;
$uploadFile = $uploads_dir . '/' . $name;
$DBFile = $uploadFile;
$uploadFile = iconv("utf-8", "EUC-KR", $uploadFile);
if (!move_uploaded_file($_FILES[$imgName]['tmp_name'], $uploadFile)) { // νμΌ μ΄λ
echo "νμΌμ΄ μ
λ‘λ λμ§ μμμ΅λλ€.";
exit;
}
echo "<script>console.log($DBFile);</script>";
}
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
?>
<script>
console.log('κ° λ°κΈ°/μ΄λ―Έμ§ ν΄λ μ μ₯');
console.log('<?=$DBFile?>');
</script>
<?php
$sql = "insert into review(loc, starscore, img, title, review, date2, datetime3)values
(
'$get_loc', '$get_score', '$DBFile', '$get_title', '$get_review', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
);"; //μ 보 μ
λ ₯
?>
<script> console.log('κ° λ£κΈ°')</script>
<?php
$result = mysqli_query($conn, $sql);
//μ μ₯μ΄ λ¬λ€λ©΄ (result = true) κ°μ
μλ£
if ($result) {
?>
<script> alert('μμ± μλ£');
location.replace('bootdiv.php');
</script>
<?php
} else {
echo "<script>alert('μμ± μ€ν¨......................');</script>";
echo mysqli_error($conn);
echo $sql . "<br>";
}
mysqli_close($conn);
?>