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 $navig['boss_message_add']="สาสน์ผู้บริหาร"; $navig['link_picture_output']="เพิ่มข้อมูล"; navigator($navig); echo "<br>"; bar_header("เพิ่มข้อมูล"); // Bar_Header fieldset_top($boss_msg->topic);
// ส่วนจัดการ upload รูปขึ้น sever และ เก็บข้อมูลลง database import_request_variables('pG', 'p_'); if($p_topic!="") { $topic=trim($p_topic); } if($p_message!="") { $message=trim($p_message); } if($p_owner!="") { $owner=trim($p_owner); } if($p_id_top!="") { $id_top=trim($p_id_top); }
$date = date("d"); $month = date("m"); $year = date("Y"); $date_time = $year . $month . $date;
$picture = trim($_FILES['picture_file']['name']); $fail_case = -1;
if ($picture != "") { $chk = check_file($picture, 'image'); if($chk != 'OK'){ $fail_case = 1; }else{ $fail_case = 0; }
$name1 = create_filename($picture); $dlink = "$_SESSION[web_name]/module_boss_message/$name1"; upload_file_to_server($dlink, $_FILES['picture_file'], '', '450', '200'); // while ($fail_case != 0) { // $strings1 = substr($picture, -4); // if ($strings1 != ".gif" && $strings1 != ".jpg" && $strings1 != ".GIF" && $strings1 != ".JPG") { // $fail_case = 1; // break; // } // $str = "123456789abcdefghijkmnpqrstuvwxyz"; // $pic = substr(str_shuffle($str), 0, 5); // $strings = substr($picture, -4); // $name1 = "pic$pic$strings"; // // $dlink = $_SESSION['web_name'] . "/module_boss_message/" . $name1; // $temp_name = $_FILES['picture_file']['tmp_name']; // if (is_uploaded_file($_FILES['picture_file']['tmp_name'])) { // if (!move_uploaded_file($temp_name, $dlink)) { // $fail_case = 2; // break; // } // } // // list($width, $height, $type, $attr) = getimagesize($_SESSION['web_name'] . "/module_boss_message/$name1"); // if ($width > 500) { // unlink($_SESSION['web_name'] . "/module_boss_message/$name1"); // $fail_case = 3; // break; // } // if ($height > 500) { // unlink($_SESSION['web_name'] . "/module_boss_message/$name1"); // $fail_case = 4; // break; // } // $fail_case = 0; // break; // } }
if ($fail_case == 0) { // first get max position $sql_position = "SELECT MAX(position) as poss FROM cms_boss_message WHERE id_top = $id_top"; $res_position = mysql_query($sql_position) or die(mysql_error); $dat_pos = mysql_fetch_object($res_position);
$max_position = $dat_pos->poss; $max_position++;
$sql = "INSERT INTO cms_boss_message (picture,position,message,topic,owner,id_top,date_create,status) values ('$name1','$max_position','$message','$topic','$owner','$id_top','$date_time',1)";
mysql_query($sql) or die(mysql_error()); echo "<center><br>ข้อมูลได้ถูกเพิ่มแล้ว<br><br></center>"; echo "<meta http-equiv='refresh' content='2; url=index.php'>"; } else { if ($fail_case == 1) echo "<center><br><br>ชนิดของรูปต้องเป็น GIF หรือ JPEG เท่านั้น<br><br></center>"; else if ($fail_case == 2) echo "<center><br><br>ไม่สามารถ Upload ไฟล์ได้ กรุณาติดต่อ administrator เพื่อเปิดการเขียนไฟล์<br><br></center>"; else if ($fail_case == 3) echo "<center><br><br>รูปสูงเกินกว่าขนาดที่กำหนด<br><br></center>"; else if ($fail_case == 4) echo "<center><br><br>รูปยาวกว่าขนาดที่กำหนด<br><br></center>"; else echo "<center><br><br>เกิดข้อผิดพลาด<br><br></center>"; // refresh //echo "<meta http-equiv='refresh' content='2; url=index.php?mod=boss_message_add&path=boss_message&id_top=$_GET[id_top]'>" ; }
fieldset_down(); ?>
|