Title1

Title2

Title3

19-8 function.php

 

<?php
defined('WEB_PATH') || die("WEB_PATH root path not defined");
/*
共用函數區,前、後台共用
*/
###############################################################################
#  訊息通知
###############################################################################
function redirect_header($url="", $time = 3000, $message = '已轉向!!')
{
  $_SESSION['redirect']="
    $(document).ready(function(){
      $.jGrowl('{$message}', {  life:{$time} , position: 'center', speed: 'slow' });
    });
  ";
  header("location:{$url}");
  exit;
}

###############################################################################
#  取得目前網址
###############################################################################
if(!function_exists("getCurrentUrl")){
function getCurrentUrl(){
  global $_SERVER;
  $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')=== FALSE ? 'http' : 'https';
  $host     = $_SERVER['HTTP_HOST'];
  $script   = $_SERVER['SCRIPT_NAME'];
  $params   = $_SERVER['QUERY_STRING']?'?' . $_SERVER['QUERY_STRING']:"";

  $currentUrl = $protocol . '://' . $host . $script .  $params;
  return $currentUrl;;
}
}

#####################################################################################
#  自動取得(排序欄位,資料表)的最新排序
#  get_max_sort_show_kind($col,$TBL)
#  (排序欄位,資料表)#
#####################################################################################
if(!function_exists("get_max_sort_show_kind")){
function get_max_sort_show_kind($col="sort",$TBL=""){
  global $mysqli;
  if(empty($col) or empty($TBL))return;
  $sql = "select max({$col})
          from `{$TBL['name']}`
          where kind='{$TBL['kind']}'";
  $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));

  list($sort)=$result->fetch_row();
  return ++$sort;
}
}

#####################################################################################
#  建立目錄
#####################################################################################
if(!function_exists("mk_dir")){
function mk_dir($dir = "")
{
  #若無目錄名稱秀出警告訊息
  if (empty($dir)) {
      return;
  }

  #若目錄不存在的話建立目錄
  if (!is_dir($dir)) {
    umask(000);
    //若建立失敗秀出警告訊息
    mkdir($dir, 0777);
  }
}
}

########################################
# #取得圖片
########################################
function get_file_name($col_sn,$col_name)
{
  global $mysqli;
  if(!$col_sn or !$col_name)return;
  #
  $sql = "select *
          from `show_files`
          where `col_sn`='{$col_sn}' and `col_name`='{$col_name}'
          order by sort";
  $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));
  $row = $result->fetch_assoc();
  #----------------
  return  $row;
}
########################################
# #取得圖片src
########################################
function get_file_name_src($col_sn,$col_name)
{
  if(!$col_sn or !$col_name)return;

  $row = get_file_name($col_sn,$col_name);
  #----------------

  #圖片檔src
  $file_name = $row['file_name'] ? WEB_URL."/uploads".$row['sub_dir']."/".$row['file_name']:"";

  return  $file_name;
}