/home/banprang/domains/plai.go.th/public_html/coremain/module/sponser/sponser_add_output.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
<?php
$navig
['link_picture']="เพิ่มข้อมูลลิงค์นอก";
$navig['link_picture_add']="เพิ่มข้อมูล";
navigator($navig);
echo 
"<br/>";
bar_header("เพิ่มข้อมูล"); // Bar_Header
fieldset_top("ลิงค์");

// ส่วนจัดการ upload รูปขึ้น sever และ เก็บข้อมูลลง database
import_request_variables('pG''p_');
if(
$p_link_name!="")        {  $link_name=trim($p_link_name);                }
if(
$p_link_target!="")        {  $link_name=trim($p_link_target);            }
if(
$p_pic_description!="")        {  $pic_description=trim($p_pic_description);            }
if(
$p_id_top!="")        {  $id_top=trim($p_id_top);            }

$picture trim($_FILES['picture_file']['name']);
$fail_case = -1;

if (
$picture != "") {

//  while ($fail_case != 0) {
    
$chk check_file($picture'image');
    if(
$chk != 'OK'){
      
$fail_case 1;
//      break;
    
}else{
      
$fail_case 0;
    }
    
    
$name1 create_filename($picture);
    
$dlink "$_SESSION[web_name]/module_sponser/$name1";
    
upload_file_to_server($dlink$_FILES['picture_file'], '''180''150');
    
//    $strings1 = substr($picture, -4);
//    $strings1 = strtolower($strings1);
//    if ($strings1 != ".gif" && $strings1 != ".jpg" && $strings1 != ".GIF" && $strings1 != ".JPG" && $strings1 != ".SWF" && $strings1 != ".swf") {
//      $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_sponser/" . $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_sponser/$name1");
//    if ($width > 180) {
//      unlink($_SESSION['web_name'] . "/module_sponser/$name1");
//      $fail_case = 3;
//      break;
//    }
//    if ($height > 700) {
//      unlink($_SESSION['web_name'] . "/module_sponser/$name1");
//      $fail_case = 4;
//      break;
//    }
//    break;
//  }
}
if (
$fail_case == 0) {
  
// first get max position 
  
$sql_position "SELECT max(position) as poss FROM cms_link_sponser WHERE id_top = $_GET[id_top]";
  
$res_position mysql_query($sql_position);
  
$dat_pos mysql_fetch_object($res_position);

  
$max_position $dat_pos->poss 1;
  if (
$strings1 != ".swf") {
    
$sql "INSERT INTO cms_link_sponser (pic_name,pic_description,link,status,id_top,position) values ('$name1','$pic_description','$link_name','1',$id_top,$max_position)";
  } else {
    
$sql "INSERT INTO cms_link_sponser (pic_name,pic_description,link,status,id_top,position) values ('$name1','$width','$height','1',$id_top,$max_position)";
  }
  
mysql_query($sql) or die(mysql_error());
  echo 
"<center><br><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>";
  
// Back    
  
echo"<center>[<a href='javascript:history.back(1)'>Back</a>]</center>";
  
//echo "<meta http-equiv='refresh' content='2; url=index.php'>" ;
}
fieldset_down();
?>