/home/banprang/domains/plai.go.th/public_html/coremain/module/web/gallery/myfunction.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
<?php
// ----------------------  WS -----------------------------------//

$month_thai = array('มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'); 
$smonth_thai = array('ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.');
function 
getThaiDate($time,$mode,$hasTime){
$month_thai = array('มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'); 
$smonth_thai = array('ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.');
                
$date date("j",$time);
                
$m date("m",$time);
                if(
$mode==1){
                    
$month $month_thai[$m-1];
                    
$year =  date("Y",$time)+543;
                }else if(
$mode==2){
                
$month $smonth_thai[$m-1];
                    
$year =  (date("Y",$time)+543);  //-2500
                
}
                
$date.= ' '.$month.' ';
                
$date.= $year;
                if(
$hasTime)
                
$date .= date(" H:i น.",$time);
                return 
$date;
}

function 
splitTagP($html){
        
$html substr(substr($html,3),0,strlen($html)-7);
        return 
$html;
}

    
    function 
getRandomName($len) { 
            
sranddate("s") ); 
            
$chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
            
$chars.= "1234567890";  
            
$ret_str ""
            
$num strlen($chars); 
            for(
$j=0$j $len$j++) { 
            
$ret_str.= $chars[rand()%$num]; 
            
            } 
            return 
$ret_str
    }
    
    function 
getExt($filename){
        return 
substr($filename,strrpos($filename,'.'));
    }
    
    function 
upload($file,$path){
        if(
is_uploaded_file($file[tmp_name])){
                
// echo 'isupload compleated<br>';
                
$ext strtolower(getExt($file[name]));  
                
$filename getRandomName(32).$ext;
                if(
$ext=='.jpg'||$ext=='.jpeg'||$ext=='.gif'){
                    if(
move_uploaded_file($file[tmp_name],$path.$filename)){        //echo 'move upload compleated<br>';    
                        
return $filename;
                    }
                }else{
                        
$_SESSION[upload][msg] = '<div><font color="red"><i>** อนุญาติเฉพาะ jpg, jpeg และ gif **</i></font></div>';
                        return 
false;
                }
            }
         return 
false;
      }
      
function 
getFileSize($size)
  {
    
$i 0;
    
$iec = array(" bytes"" KB"" MB"" GB"" TB"" PB"" EB"" ZB"" YB");
    while ((
$size 1024) > 1)
    {
      
$size $size 1024;
      
$i++;
    }
    return 
substr($size0strpos($size'.') + 2) . $iec[$i];
  }

// ----------------------------------- WS ---------------------------------//
function check_upload_file_size($fs,$size_allow,$current_size){
    
$tmp_file_size $fs/1048576;
    
$tmp_size $tmp_file_size $current_size;
    if(
$tmp_size $size_allow){
        return 
false;
    }else{
        return 
true;
    }
}
?>