Viewing file: Function.php (7.14 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!-- <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> -->
<?php
// Function ทาง Date,Mate
$ThaiMonth = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
$ThaiSubMonth = array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$Degree = array("ปริญญาตรี","ปริญญาโท","ปริญญาเอก");
/////////////////////////////////// Display Thai Day ///////////////////////////////////
function getThaiMonth()
{
global $ThaiMonth;
for( $i=0; $i<=11; $i++ )
{
$a = $i+1;
/*if( $a == 1 )
echo"\n\t<option value=\"$a\" selected>$ThaiMonth[$i]</option>\n ";
else
echo"\n\t<option value=\"$a\">$ThaiMonth[$i]</option>\n ";*/
echo"\n\t<option value=\"$a\" ".((date("m") == $a)?"selected":"").">$ThaiMonth[$i]</option>\n ";
}
}
/////////////////////////////////////////////////////////////////////////////////
function getThaiSubMonth( $a )
{
global $ThaiSubMonth;
$a = $a -1;
for( $i=0; $i<=11; $i++ )
{
if( $a == $i )
return $a = $ThaiSubMonth[$i];
}
}
///////////////////////////// Display Thai Month ////////////////////////////////////////////////////////////////////////
function getDay1to31()
{
for( $i=1; $i<=31; $i++ )
{
/*if( $i == 1 )
echo"\n\t<option value=\"$i\" selected>$i</option>\n ";
else
echo"\n\t<option value=\"$i\">$i</option>\n ";*/
echo"\n\t<option value=\"$i\" ".((date("j") == $i)?"selected":"").">$i</option>\n ";
}
}
/////////////////// Display Thai Year ////////////////////////////////////////////////////////////////////
function get2Year()
{
$today = getdate();
$year = $today[year];
for( $x=$year-50; $x<=2010; $x++ )
{
$z = $x+547;
if( $x == ($year+10) )
echo"\n\t<option value=\"$x\" selected>$z</option>\n ";
else
echo"\n\t<option value=\"$x\">$z</option>\n ";
}
}
/////////////////// Display Year ////////////////////////////////////////////////////////////////////
function getYear( $year )
{
return $year = ( $year + 543 );
}
///////////////////////////// Display Degree
function getThaiDegree()
{
global $ThaiMonth;
for( $i=0; $i<=2; $i++ )
{
$a = $i+1;
if( $a == 1 )
echo"\n\t<option value=\"$a\" selected>$Degree[$i]</option>\n ";
else
echo"\n\t<option value=\"$a\">$Degree[$i]</option>\n ";
}
}
//////////////////////////////////////////
function TxtThaiMonth( $a )
{
global $ThaiMonth;
$a = $a -1;
for( $i=0; $i<=11; $i++ )
{
if( $a == $i )
return $a = $ThaiMonth[$i];
}
}
//////////////////* ฟังก์ชั่นตรวจสอบความยาวของสตริง เช่น CheckLenght( $mPassword, 6 ) */
function CheckLenght( $txt , $width )
{
if( strlen( $txt ) >= $width )
return true;
return false;
}
//////////////////////////////* ฟังก์ชั่นตรวจสอบรูปแบบของ Email Address */
function validEmail ( $email )
{
if ( ! eregi( "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$", $email ) )
return false;
return true;
}
////////////////* ฟังก์ชั่นตรวจสอบข้อมูลที่นำเข้าว่า เป็นตัวอักษรภาษาอังกฤษ กับ ตัวเลขหรือไม่ */
function CheckEngNumAlpha ( $txt )
{
if ( ! ereg( "[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]", $txt ) )
return true;
}
function dmyE2ymdT($ddmmyyyy){
// 13/10/2011 ==> 2554-10-13
$dmy = substr($ddmmyyyy,0,10);
$ymd = (substr($dmy,-4) + 543) . "-" . substr($dmy,3,2) . "-" . substr($dmy,0,2);
return $ymd;
}
function dmyE2dmyT($ddmmyyyy){
// 13/10/2005 ==> 13 ตุลาคม 2548
global $ThaiMonth;
if ($ddmmyyyy=="")
$dmyT=="";
else{
$ymdE = substr($ddmmyyyy,0,10);
//$m = (int) substr($ymdE,3,2);
$dmyT = ((substr($ymdE,0,2) < 10)?substr($ymdE,1,1):substr($ymdE,0,2))." ".$ThaiMonth[(substr($ymdE,3,2)-1)]." ".(substr($ymdE,-4)+543) ;
}
return $dmyT;
}
function ymdT2dmyE($yyyymmdd){
// 2554-10-13 ==> 13/10/2011
if ($yyyymmdd=="")
$ymd="";
else{
$ymd = substr($yyyymmdd,0,10);
$dmy = substr($ymd,-2) . "/" . substr($ymd,5,2) . "/" .(substr($ymd,0,4) - 543);
//$dmy = (substr($ymd,-4) + 543) . "-" . substr($ymd,3,2) . "-" . substr($ymd,0,2);
}
return $dmy;
}
function dmyE2ymdE2($ddmmyyyy){ // 13/10/2011 ==> 2011-10-13
list($d,$m,$y) = split('/',$ddmmyyyy);
return $y."-".$m."-".$d;
}
function ymdE2dmyE2($yyyymmdd){ // 2011-10-13 ==> 13/10/2011
list($y,$m,$d) = split('-',$yyyymmdd);
return $d."/".$m."/".$y;
}
function citizenID_format($citizenID){ // 1234567890123 => 1-2345-67890-12-3
if(strlen($citizenID) == 13) return substr($citizenID,0,1)."-".substr($citizenID,1,4)."-".substr($citizenID,5,5)."-".substr($citizenID,-3,2)."-".substr($citizenID,-1);
else return $citizenID;
}
function ymdE2dmyText($yyyymmdd){ // 2012-08-02 ==> 2 สิงหาคม 2555
list($y,$m,$d) = split('-',$yyyymmdd);
return intval($d)." ".TxtThaiMonth($m)." ".($y+543);
}
function ymdE2dmySubText($yyyymmdd){ // 2012-08-02 ==> 2 ส.ค. 55
list($y,$m,$d) = split('-',$yyyymmdd);
return intval($d)." ".getThaiSubMonth($m)." ".substr(($y+543),-2);
}
function ymdT2dmyText($yyyymmdd){ // 2555-08-02 ==> 2 สิงหาคม 2555
list($y,$m,$d) = split('-',$yyyymmdd);
return intval($d)." ".TxtThaiMonth($m)." ".$y;
}
function ymdT2dmySubText($yyyymmdd){ // 2555-08-02 ==> 2 ส.ค. 55
list($y,$m,$d) = split('-',$yyyymmdd);
return intval($d)." ".getThaiSubMonth($m)." ".substr($y,-2);
}
function downloadFile($fullPath){
// Must be fresh start
if(headers_sent())
die('Headers Sent');
// Required for some browsers
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
// File Exists?
if( file_exists($fullPath)){
// Parse Info / Get Extension
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
// Determine Content Type
switch ($ext) {
case "txt": $ctype="application/txt"; break;
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "rar": $ctype="application/rar"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg": $ctype="image/jpg"; break;
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($fullPath)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
ob_clean();
flush();
readfile($fullPath);
} else
die('File Not Found');
}
?>
|