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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
<?php ob_start(); session_start();
include("config.php"); include("lib.php");
$IP = $_POST["verify"]; $pecah = explode(".",$REMOTE_ADDR); $pecah3 = $pecah[0] . $pecah[1] . $pecah[2] . session_id();
if ($IP != md5($floodpass.$pecah3)) { exit(); }
if($_SESSION['num_to_check'][0]+$_SESSION['num_to_check'][1] != $_POST["vcaptcha"]){ erro("คุณบวกเลขผิด"); } $_SESSION['tdata']['nama']=$nama; $_SESSION['tdata']['email']=$email; $_SESSION['tdata']['homepage']=$homepage; $_SESSION['tdata']['topic']=$topic ; $_SESSION['tdata']['topictext']=$topictext;
//if (trim($nama)=="" or trim($email=="") or trim($topic=="") or trim($topictext)=="") { if (trim($nama)=="" or trim($topic=="") or trim($topictext)=="") { erro("ยังใส่ข้อมูลไม่ครบทุกช่อง โดยเฉพาะช่องที่มีเครื่องหมาย <font color=red><b>*</b></font> จำเป็นต้องใส่",'newtopic.php'); } check_name_reserve(trim($nama)); if (trim($homepage)=="http://") $homepage = ""; if ($email) check_email($email);
$nama = htmlspecialchars($nama); $email = htmlspecialchars($email); $homepage = htmlspecialchars($homepage); $topic = htmlspecialchars($topic);
// category $ccat=($_REQUEST['cat']) ? count($_REQUEST['cat']) : 0; if ($ccat==0) erro("กรุณาเลือกหมวดหมู่ อย่างน้อย 1 กลุ่ม",'newtopic.php'); if ($ccat>3) erro("ท่านสามารถเลือกหมวดหมู่ได้ไม่เกิน 3 กลุ่ม",'newtopic.php'); unset($category); foreach ( $_REQUEST['cat'] as $key => $value ) { $category=$category."/".$value; } $category=$category."/"; $test_comment = explode(" ",$topictext); $jmltest = count($test_comment);
for ($t=0; $t<$jmltest; $t++) { if (strlen(trim($test_comment[$t])) > 1000) { erro("จำนวนตัวหนังสือห้ามติดกันเกิน 1000 ตัวอักษร ",'new_topic.php'); } }
// check image if (! empty($_FILES['attachment'])) { $count = count($_FILES['attachment']['name']); if ($count > 0) { for ($i = 0; $i < $count; $i ++) { if (! empty($_FILES["attachment"]["name"])) { $uploadOk = 1; $TempFile = $_FILES["attachment"]["tmp_name"][$i]; $TempfileName = $_FILES["attachment"]["name"][$i]; $imageFileType = strtolower(pathinfo($TempfileName,PATHINFO_EXTENSION)); if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "ขออภัย, $TempfileName ไม่ใช่รูปภาพ, อนุญาติให้แนบไฟล์รูปภาพ (JPG, JPEG, PNG & GIF) เท่านั้น."; $uploadOk = 0; } } } } } // end check image
$topictext = htmlspecialchars($topictext); $topictext = str_replace("\n","<BR>",$topictext); $tgl = date("Y-m-d H:i");
// update cat used $Scat=explode("/",$category); for ($i=1; $i<=3; $i++) { if ($Scat[$i]) { $res=@mysql_query("insert into mtalk_catused VALUES (".$Scat[$i].",0);"); } }// e for 1
if (strstr($topictext,"http")) $SPAM=1; if (strstr($nama,"http")) $SPAM=1; if (strstr($topic,"http")) $SPAM=1; if ($SPAM) { echo "<p>ไม่สามารถบันทึกได้ เนื่องจากระบบตรวจพบว่าท่านกำลัง SPAM ข้อความ, ระบบไม่อนุญาติให้ใส่ html ในข้อความ</p>"; echo "<br><br> <a href='newtopic.php'>คลิกที่นี่เพื่อกลับไปยังข้อความ</a>"; }else{
//Process ADD topic and info $ins1 = mysql_query("INSERT INTO mtalk_topic VALUES (null,'$category', '$topic', '$nama', '$tgl', 0, 0, 0,1)"); $topic_rnd = mysql_insert_id(); $ins2 = mysql_query("INSERT INTO mtalk_post VALUES(null, '$topic_rnd', '$nama', '$tgl', '$email', '$homepage')"); $post_rnd = mysql_insert_id();
$ins3 = mysql_query("INSERT INTO mtalk_postext VALUES($post_rnd, '$topictext','')"); $ins4 = mysql_query("UPDATE mtalk_topic SET topic_last_post_id=$post_rnd WHERE topic_id = $topic_rnd");
// Work with image upload if (! empty($_FILES['attachment'])) { $count = count($_FILES['attachment']['name']); if ($count > 0) { for ($i = 0; $i < $count; $i ++) { if (! empty($_FILES["attachment"]["name"])) { // Allow certain file formats $uploadOk = 1; $TempFile = $_FILES["attachment"]["tmp_name"][$i]; $TempfileName = $_FILES["attachment"]["name"][$i]; $imageFileType = strtolower(pathinfo($TempfileName,PATHINFO_EXTENSION)); /* if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, $TempfileName not image file, Please upload only JPG, JPEG, PNG & GIF files."; $uploadOk = 0; } */ $NfileName="$post_rnd-$i-".basename($TempfileName); $SaveFile = $target_dir.$NfileName; if (move_uploaded_file($TempFile, $SaveFile)) { echo "The file $fileName has been uploaded and change file name to $NfileName"; $fileAttached=$fileAttached."/".$NfileName; mysql_query("UPDATE mtalk_postext SET attached='$fileAttached' WHERE post_id = $post_rnd"); }else{ echo "Sorry, there was an error uploading your file."; } } } } } //end Work with image upload $url = "Location: index.php"; unset($_SESSION['tdata']); header($url); } ?>
|