smarty页函数
<?php
/*******************************************
writer:zhaofei299
Emai:zhaofei299@163.com
百度空间:http://hi.baidu.com/zhaofei299
*******************************************/
class Page
{
var $pageSize; //每页显示的数据数
var $page; //当前页面数
var $amount; //总数据数
var $amountPage; //总页数
var $pageNum; //每页显示的链接数
function __construct($size, $pageNum) //构造函数,初始化成员属性
{
$this->pageSize= $size; //每页显示数据数
$this->amount= 0;
$this->ampuntPage= 0;
$this->pageNum=$pageNum; //每页显示多少页数链接
link_data(); //连接数据库
}
function getPage() //得到当前页面数
{
$id= trim($_GET['id']); //当前页面id
$this->getAmount(); //得到总数据数
$amountPage= $this->getAmountPage(); //总页数
if (isset($id) && $id>0) //如果参数id存在 并且 参数id大于0
$this->page= intval($id); //取其整数部分
else
$this->page=1; //将1赋给当前页面
if (isset($id) && ($id>$amountPage))//如果参数id存在 并且 参数id大于总页数
$this->page=$amountPage; //将总页数赋给当前页数
}
function getStart() //得到LIMIT数据 开始的索引
{
$start= ($this->page-1)*5;
return $start; //返回开始索引
}
function getInfo($start, $sql) //得到数据表中的数据信息,并以数组的形式返回
{
$array=array(); //初始化数组
$result= mysql_query($sql); //执行sql语句
while (@$reArray= mysql_fetch_array($result)) //从数据表中取出一行,作相关,索引数组操作
{
$array[]= $reArray; //将包含数据信息的数组添加入新的数组中
}
return $array; //返回一个二维数组
}
function getAmount() //得到总数据数
{
$sql= "SELECT count(*) as count FROM talk_info"; //查询
$result= mysql_query($sql);
$reArray= mysql_fetch_array($result);
return $this->amount= $reArray['count']; //总数据数
}
function getAmountPage() //得到总页数
{
$this->amountPage= $this->amount/$this->pageSize; //总页数= 总数据数 / 每页显示数据数
if (!is_int($this->amountPage)) //如果计算得到的总页数不是整形
$this->amountPage= intval($this->amountPage)+1; //取其整数部分+1;
return $this->amountPage;
}
function getPageLinks() //得到当前页面显示的所有的链接,并以数组的形式返回
{
$amountPage= $this->amountPage; //总页面数
$pageNum= $this->pageNum; //每页显示的链接数
$page= $this->page; //当前页数
$urlArray= array();
if ($page>1) //如果当前页面数大于1
{
$urlArray[]= "<a href='talk.php?id=1'> [|<<] </a>";
$urlArray[]= "<a href='talk.php?id=".($page-1)."'> [<<] </a>";
}
else
{
$urlArray[]= '[|<<]';
$urlArray[]= '[<<]';
}
$p= intval($page/5)+1; //区间
$a= ($p-1)*5+1;
for ($j=$a; $j<$a+$pageNum; $j++)
{
if ($j>$amountPage)
break;
if ($j==$page)
$urlArray[]= '['.$j.']';
else
$urlArray[]= "<a href='talk.php?id=".$j."'> [".$j."] </a>";
}
//}
if ($page<$amountPage) //当前页面数小于总页面数
{
$urlArray[]= "<a href='talk.php?id=".($page+1)."'> [>>] </a>";
$urlArray[]= "<a href='talk.php?id=".$amountPage."'> [>|] </a>";
}
else
{
$urlArray[]= '[>>]';
$urlArray[]= '[>|]';
}
return $urlArray; //返回包含所有链接的数组
}
}
?>
<?php
/**
*TTR上传类
*2007-09-22
*[url=http://www.gx3.cn/]http://www.Gx3.cn[/url]
*QQ:252319874
**/
class TTRUpload extends Error
{
const filesize=81200000;
private $uploadpath="uploadfile/";
private $savepath=null;
private $uploadfilename=null; //单个文件为文件名,批量文件为xxxx|xxxx格式,请注意
private $ext=array("jpg","gif","png");
private $error=null;
private $file=null;
private $uploadtype=null;
private $filename=null;
//构造函数,$type:ONE单个上传 ANY批量上传;
public function __construct($file,$type="ONE")
{
if($type!="ONE" && $type!="ANY")
{
echo "<script language='javascript'>alert('初始化请选择ONE或者ANY')</script>";
exit;
}
$this->uploadtype=$type;
$this->file=$file;
}
private function createFileName()
{
return $this->filename="TTR_".time().$this->getRandomN(4);
}
private function getUploadPath()
{
if(substr($this->uploadpath,-1,1)!="/")
{
$this->savepath=$this->uploadpath."/".date("Ym");
}else{
$this->savepath=$this->uploadpath.date("Ym");
}
$this->savepath=$this->getFolder($this->savepath);
return true;
}
private function getFileExt($tempfilename)
{
return end(explode(".",$tempfilename));
}
private function getExt()
{
if(in_array(strtolower($this->getFileExt($tempfilename)),$this->ext))
{
return true;
}else{
return false;
}
}
private function getFolder($folder)
{
if(!is_dir($folder))
{
mkdir($folder);
}
return $folder."/";
}
public function upload()
{
if($this->uploadtype=="ONE")
{
if($this->getExt($this->file["type"]))
{
parent::errorExt();
}else if($this->file["size"]>self::filesize){
parent::errorFileSize();
}else if(!$this->getUploadPath()){
parent::errorUploadPath();
}else{
$filenametemp=$this->createFileName();
$filename=$this->savepath.$filenametemp.".".$this->getFileExt($this->file["name"]);
if(move_uploaded_file($this->file["tmp_name"],$filename))
{
$this->uploadfilename=$filenametemp;
parent::okMoved();
}else{
parent::errorMoveUpload();
}
}
}else if($this->uploadtype=="ANY"){
for($i=0;$i<count($this->file);$i++)
{
if($this->getExt($this->file[$i]["type"]))
{
parent::errorExt();
}else if($this->file[$i]["size"]>self::filesize){
parent::errorFileSize();
}else if(!$this->getUploadPath()){
parent::errorUploadPath();
}else{
$filenametemp=$this->createFileName();
$filename=$this->savepath.$filenametemp.".".$this->getFileExt($this->file[$i]["name"]);
if(move_uploaded_file($this->file[$i]["tmp_name"],$filename))
{
$str.=$filenametemp."|";
}else{
parent::errorMoveUpload();
}
}
}
$this->uploadfilename=substr($str,0,strlen($str)-1);
parent::okMoved();
}
}
public function getUploadFileName()
{
return $this->uploadfilename;
}
public function setUploadPath($path)
{
$this->uploadpath=$path;
}
private function getRandomN($n)
{
if ($n < 1 || $n>10) return "";
$ary_num= array(0,1,2,3,4,5,6,7,8,9);
$return ="";
for ($i=0;$i<$n;$i++)
{
$randn = rand(0,9-$i);
$return .= $ary_num[$randn];
$ary_num[$randn] = $ary_num[9-$i];
}
return $return;
}
public function __destruct()
{
$this->uploadfilename=null;
$this->uploadtype=null;
$this->file=null;
$this->savepath=null;
}
}
class Error
{
public static function errorFileSize()
{
echo "超出最大上传限制";
}
public static function errorExt()
{
echo "此类文件不允许上传";
}
public static function errorUploadPath()
{
echo "上传路径不正确";
}
public static function errorMoveUpload()
{
echo "上传失败";
}
public static function okMoved()
{
echo "上传成功!";
}
public static function okArrayMoved()
{
echo "上传成功!";
}
}
实例应用:
<?php
require_once("include/upload.class.php");
if($_POST["button"])
{
//print_r($_FILES);
//多个上传
$upload = new TTRUpload(array($_FILES["file1"],$_FILES["file2"],$_FILES["file3"],$_FILES["file4"]),"ANY");
//单个上传
//$upload = new TTRUpload($_FILES["file1"]);
$upload->upload();
echo $upload->getUploadFileName();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input type="file" name="file1" id="file1" />
<br />
<input type="file" name="file2" id="file2" />
<br />
<input type="file" name="file3" id="file3" />
<br />
<input type="file" name="file4" id="file4" />
<br />
<input type="submit" name="button" id="button" value="Submit" />
</form>
</body>
</html>
<?php
/*
--------------------------
Copyright by T.muqiao(39号天堂桥)
本程序仅供学习讨论使用,在未通知作者作为任何商业用途
视为中华人民共和国不道德公民
联系方式:442536278@qq.com
-------------------------*/
if(!defined('IN_SELF')){
header('HTTP/1.1 404 NOT Found');
exit;
}
class ZipAllFloder{//压缩文件夹
var $datasec = array();
var $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
var $dirs = array(".","");
var $dirlen = 0;
function IniVars(){//初始化变量
$this -> datasec = array();
$this -> ctrl_dir = array();
$this -> eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
$this -> old_offset = 0;
$this -> dirs = array(".","");
$this -> dirlen = 0;
}
function ZipFolder($dir,$zipfilename){//压缩一个文件夹
if(substr($dir,-1)!="/"){
$dir .= "/";
}
$this -> dirlen = strlen($dir);
$this -> AddFolderContent($dir);
$out = $this -> get_file();
$this -> IniVars();
$fp = fopen($zipfilename,"w");
fwrite($fp,$out,strlen($out));
fclose($fp);
}
function AddFolderContent($dir){//添加文件夹中文件内容
if(is_dir($dir)){
$folder = substr($dir,$this ->dirlen);
if(!in_array($folder,$this->dirs)){
$this->add_Dir($folder);
}
$handle = opendir($dir);
while($files = readdir($handle)){
if (($files==".")||($files=="..")) continue;
if(is_dir($dir.$files)){
$this->AddFolderContent($dir.$files."/");
}else{
$fp = fopen ($dir.$files,"r");
$content = @fread ($fp,filesize($dir.$files));
fclose ($fp);
$this->add_File($content,$folder.$files);
}
}
closedir($handle);
}
}
function get_file(){//获得压缩文件数据
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
return $data . $ctrldir . $this -> eof_ctrl_dir .
pack('v', sizeof($this -> ctrl_dir)).pack('v', sizeof($this -> ctrl_dir)).
pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00";
}
function add_dir($name){
$name = str_replace("\\", "/", $name);
$fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$fr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$fr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0);
$this -> datasec[] = $fr;
$new_offset = strlen(implode("", $this->datasec));
$cdrec = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$cdrec .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$cdrec .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 );
$ext = "\xff\xff\xff\xff";
$cdrec .= pack("V", 16 ).pack("V", $this -> old_offset ).$name;
$this -> ctrl_dir[] = $cdrec;
$this -> old_offset = $new_offset;
$this -> dirs[] = $name;
}
function add_File($data, $name, $compact = 1){
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->DosTime());
$hexdtime = '\x' . $dtime[6] . $dtime[7].'\x'.$dtime[4] . $dtime[5] . '\x' . $dtime[2] . $dtime[3].'\x'.$dtime[0].$dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
if($compact){
$fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00".$hexdtime;
}else{
$fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00".$hexdtime;
}
$unc_len = strlen($data); $crc = crc32($data);
if($compact){
$zdata = gzcompress($data); $c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
}else{
$zdata = $data;
}
$c_len=strlen($zdata);
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata;
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$this -> datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
if($compact){
$cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00";
}else{
$cdrec = "\x50\x4b\x01\x02\x14\x00\x0a\x00\x00\x00\x00\x00";
}
$cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$cdrec .= pack('v', strlen($name) ).pack('v', 0 ).pack('v', 0 );
$cdrec .= pack('v', 0 ).pack('v', 0 ).pack('V', 32 );
$cdrec .= pack('V', $this -> old_offset );
$this -> old_offset = $new_offset;
$cdrec .= $name;
$this -> ctrl_dir[] = $cdrec;
return true;
}
function DosTime() {
$timearray = getdate();
if ($timearray['year'] < 1980) {
$timearray['year'] = 1980; $timearray['mon'] = 1;
$timearray['mday'] = 1; $timearray['hours'] = 0;
$timearray['minutes'] = 0; $timearray['seconds'] = 0;
}
return (($timearray['year']-1980)<<25)|($timearray['mon']<<21)|($timearray['mday']<<16)|($timearray['hours']<<11)|($timearray['minutes']<<5)|($timearray['seconds']>>1);
}
}
class UnCompress{
function get_List($zip_name){
$zip = @fopen($zip_name, 'rb');
if(!$zip) return(0);
$centd = $this->ReadCentralDir($zip,$zip_name);
@rewind($zip);
@fseek($zip, $centd['offset']);
for ($i=0; $i<$centd['entries']; $i++){
$header = $this->ReadCentralFileHeaders($zip);
$header['index'] = $i;
$info['filename'] = $header['filename'];
$info['stored_filename'] = $header['stored_filename'];
$info['size'] = $header['size'];
$info['compressed_size'] = $header['compressed_size'];
$info['crc'] = strtoupper(dechex( $header['crc'] ));
$info['mtime'] = $header['mtime'];
$info['comment'] = $header['comment'];
$info['folder'] = ($header['external']==0x41FF0010||$header['external']==16)?1:0;
$info['index'] = $header['index'];$info['status'] = $header['status'];
$ret[] = $info;
unset($header);
}
return $ret;
}
function Extract($zn,$to,$index = array(-1) ){
$ok = 0;
$zip = @fopen($zn,'rb');
if(!$zip){
return(-1);
}
$cdir = $this->ReadCentralDir($zip,$zn);
$pos_entry = $cdir['offset'];
if(!is_array($index)){
$index = array($index);
}
for($i=0; $index[$i];$i++){
if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries']){
return(-1);
}
}
for ($i=0; $i<$cdir['entries']; $i++){
@fseek($zip, $pos_entry);
$header = $this->ReadCentralFileHeaders($zip);
$header['index'] = $i; $pos_entry = ftell($zip);
@rewind($zip); fseek($zip, $header['offset']);
if(in_array("-1",$index)||in_array($i,$index)){
$stat[$header['filename']]=$this->ExtractFile($header, $to, $zip);
}
}
fclose($zip);
return $stat;
}
function ReadFileHeader($zip){
$binary_data = fread($zip, 30);
$data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);
$header['filename'] = fread($zip, $data['filename_len']);
if ($data['extra_len'] != 0) {
$header['extra'] = fread($zip, $data['extra_len']);
}else{
$header['extra'] = '';
}
$header['compression'] = $data['compression'];$header['size'] = $data['size'];
$header['compressed_size'] = $data['compressed_size'];
$header['crc'] = $data['crc']; $header['flag'] = $data['flag'];
$header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime'];
if ($header['mdate'] && $header['mtime']){
$hour=($header['mtime']&0xF800)>>11;$minute=($header['mtime']&0x07E0)>>5;
$seconde=($header['mtime']&0x001F)*2;$year=(($header['mdate']&0xFE00)>>9)+1980;
$month=($header['mdate']&0x01E0)>>5;$day=$header['mdate']&0x001F;
$header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
}else{
$header['mtime'] = time();
}
$header['stored_filename'] = $header['filename'];
$header['status'] = "ok";
return $header;
}
function ReadCentralFileHeaders($zip){
$binary_data = fread($zip, 46);
$header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);
if ($header['filename_len'] != 0){
$header['filename'] = fread($zip,$header['filename_len']);
}else{
$header['filename'] = '';
}
if ($header['extra_len'] != 0){
$header['extra'] = fread($zip, $header['extra_len']);
}else{
$header['extra'] = '';
}
if ($header['comment_len'] != 0){
$header['comment'] = fread($zip, $header['comment_len']);
}else {
$header['comment'] = '';
}
if ($header['mdate'] && $header['mtime']){
$hour = ($header['mtime'] & 0xF800) >> 11;
$minute = ($header['mtime'] & 0x07E0) >> 5;
$seconde = ($header['mtime'] & 0x001F)*2;
$year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
$month = ($header['mdate'] & 0x01E0) >> 5;
$day = $header['mdate'] & 0x001F;
$header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
}else{
$header['mtime'] = time();
}
$header['stored_filename'] = $header['filename'];
$header['status'] = 'ok';
if (substr($header['filename'], -1) == '/'){
$header['external'] = 0x41FF0010;
}
return $header;
}
function ReadCentralDir($zip,$zip_name){
$size = filesize($zip_name);
if ($size < 277){
$maximum_size = $size;
}else{
$maximum_size=277;
}
@fseek($zip, $size-$maximum_size);
$pos = ftell($zip);
$bytes = 0x00000000;
while ($pos < $size){
$byte = @fread($zip, 1); $bytes=($bytes << 8) | Ord($byte);
if ($bytes == 0x504b0506){
$pos++;
break;
}
$pos++;
}
$data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size',
fread($zip, 18));
if ($data['comment_size'] != 0){
$centd['comment'] = fread($zip, $data['comment_size']);
}else{
$centd['comment'] = ''; $centd['entries'] = $data['entries'];
}
$centd['disk_entries'] = $data['disk_entries'];
$centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start'];
$centd['size'] = $data['size']; $centd['disk'] = $data['disk'];
return $centd;
}
function ExtractFile($header,$to,$zip){
$header = $this->readfileheader($zip);
if(substr($to,-1)!="/"){
$to.="/";
}
if(!@is_dir($to)){
@mkdir($to,0777);
}
$pth = explode("/",dirname($header['filename']));
for($i=0;isset($pth[$i]);$i++){
if(!$pth[$i]){
continue;
}
if(!is_dir($to.$pth[$i])){
@mkdir($to.$pth[$i],0777);
}
}
if (!($header['external']==0x41FF0010)&&!($header['external']==16)){
if ($header['compression']==0){
$fp = @fopen($to.$header['filename'], 'wb');
if(!$fp){
return(-1);
}
$size = $header['compressed_size'];
while ($size != 0){
$read_size = ($size < 2048 ? $size : 2048);
$buffer = fread($zip, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
fclose($fp);
touch($to.$header['filename'], $header['mtime']);
}else{
$fp = @fopen($to.$header['filename'].'.gz','wb');
if(!$fp){
return(-1);
}
$binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']),
Chr(0x00), time(), Chr(0x00), Chr(3));
fwrite($fp, $binary_data, 10);
$size = $header['compressed_size'];
while ($size != 0){
$read_size = ($size < 1024 ? $size : 1024);
$buffer = fread($zip, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
$binary_data = pack('VV', $header['crc'], $header['size']);
fwrite($fp, $binary_data,8); fclose($fp);
$gzp = @gzopen($to.$header['filename'].'.gz','rb') or die("Cette archive est compress");
if(!$gzp){
return(-2);
}
$fp = @fopen($to.$header['filename'],'wb');
if(!$fp){
return(-1);
}
$size = $header['size'];
while ($size != 0){
$read_size = ($size < 2048 ? $size : 2048);
$buffer = gzread($gzp, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
fclose($fp); gzclose($gzp);
touch($to.$header['filename'], $header['mtime']);
@unlink($to.$header['filename'].'.gz');
}
}
return true;
}
}
class StatFolder{//统计文件夹内容
var $Num = 0;
var $Size = 0;
var $TypeNum = 0;
var $FolderNum = 0;
var $Type = array();
function __construct($folder){
$this -> ReadFolder($folder);
}
function StatFolder($folder){
$this -> ReadFolder($folder);
}
function ReadFolder($folder){
if(is_dir($folder)){
$handle = opendir($folder);
while($files = readdir($handle)){
if (($files==".")||($files=="..")) continue;
if(is_dir($folder."/".$files)){
$this ->FolderNum++;
$this ->ReadFolder($folder."/".$files);
}else{
$this ->Num++;
$type = fileext($files);
if(!in_array($type,$this ->Type)){
$this ->Type[] = $type;
$this ->TypeNum++;
}
$size = filesize($folder."/".$files);
$this->Size +=$size;
clearstatcache();
}
}
closedir($handle);
}
}
function GetFileNum(){
return $this -> Num;
}
function GetTotalSize(){
$switch = $this->Size/1024;
if($switch<1024){
$return = explode(".",$switch);
if($return[0]==0){
return $this->Size." bytes";
}
return $return[0].".".substr($return[1],0,3)." Kbytes";
}else{
$switch /=1024;
$return = explode(".",$switch);
return $return[0].".".substr($return[1],0,3)." Mbytes";
}
}
function GetTypeNum(){
return $this -> TypeNum;
}
function GetFolderNum(){
return $this -> FolderNum;
}
}
function matchpath($reference,$testpath){//检查$testpath是否数学上的属于$reference参照路径
$reference = explode("/",$reference);
$testpath = explode("/",$testpath);
$num1 = count($reference);
$num2 = count($testpath);
if($num1 < $num2){
return false;
}
$degree = 0;
for($i=0;$i<$num2;$i++){
if(strtolower($testpath[$i])==strtolower($reference[$i])){
$degree++;
continue;
}else{
return false;
break;
}
}
if($degree==$num2){
return true;
}
}
function checkcore($path){//检查核心文件是否包含其中
global $T_corefile;
for($i=0;$p=$T_corefile[$i];$i++){
if(matchpath($p,$path)){
return true;
break;
}
}
}
function copypath($source,$target,$uncover=true){//拷贝整个目录 默认不允许覆盖
global $T_lang;
if(is_dir($target)){
if($uncover){
$errors .= str_replace("--replace--",$target,$T_lang['func'][0]);
$gocover = false;
}else{
$gocover = true;
}
}else{
if(matchpath($target,$source)){//检测目录$source是否包含于$target
$errors .= str_replace("--replace--",$source,$T_lang['func'][1]);
$gocover = false;
}else{
if(@mkdir($target,0777)){
$gocover = true;
}else{
$errors .= str_replace("--replace--",$target,$T_lang['func'][2]);
$gocover = false;
}
}
}
if($gocover){
$handle = opendir($source);
while($file = readdir($handle)){
clearstatcache();
if(substr($file,-1)=="."||substr($file,-2)=="..") continue;
if(is_dir($source."/".$file)){
$errors .= copypath($source."/".$file,$target."/".$file,$uncover);
}else{
$gocopy = true;
if(file_exists($target."/".$file)){
if($uncover){
$gocopy = false;
}else{
if(@unlink($target."/".$file)){
$gocopy = true;
}else{
$gocopy = false;
}
}
}
if($gocopy){
if(@copy($source."/".$file,$target."/".$file)){
$errors .= "";
}else{
$errors .= str_replace("--replace--",$source."/".$file,$T_lang['func'][3]);
}
}else{
$errors .= str_replace("--replace--",$target."/".$file,$T_lang['func'][4]);
}
}
}
closedir($handle);
}
if($errors){
return $errors;
}else{
return "";
}
}
function movepath($source,$target,$uncover=true){//移动整个目录 默认不允许覆盖
global $T_lang;
if(is_dir($target)){
if($uncover){
$errors .= str_replace("--replace--",$target,$T_lang['func'][0]);
$gocover = false;
}else{
$gocover = true;
}
}else{
if(matchpath($target,$source)){//检测目录$source是否包含于$target
$errors .= str_replace("--replace--",$source,$T_lang['func'][5]);
$gocover = false;
}else{
if(@mkdir($target,0777)){
$gocover = true;
}else{
$errors .= str_replace("--replace--",$target,$T_lang['func'][2]);
$gocover = false;
}
}
}
if($gocover){
$handle = opendir($source);
while($file = readdir($handle)){
clearstatcache();
if(substr($file,-1)=="."||substr($file,-2)=="..") continue;
if(!is_dir($source."/".$file)){
$gocopy = true;
if(file_exists($target."/".$file)){
if($uncover){
$gocopy = false;
}else{
$gocopy = true;
}
}
if($gocopy){
if(@copy($source."/".$file,$target."/".$file)){
unlink($source."/".$file);
}else{
$errors .= str_replace("--replace--",$source."/".$file,$T_lang['func'][3]);
}
}else{
$errors .= str_replace("--replace--",$target."/".$file,$T_lang['func'][6]);
}
}else{
$errors .= movepath($source."/".$file,$target."/".$file,$uncover);
}
}
closedir($handle);
}
if($errors){
return $errors;
}else{
if(@rmdir($source."/".$file)){
return "";
}else{
$errors .= str_replace("--replace--",$source,$T_lang['func'][7]);
}
}
}
function delpath($source){//删除整个目录
global $T_lang,$T_Recycled;
$handle = opendir($source);
while($file = readdir($handle)){
clearstatcache();
if(substr($file,-1)=="."||substr($file,-2)=="..") continue;
if(is_dir($source."/".$file)){
$errors .= delpath($source."/".$file);
}else{
if(@unlink($source."/".$file)){
}else{
$errors .= str_replace("--replace--",$source,$T_lang['func'][7]);
}
}
}
closedir($handle);
if($errors){
$errors .= str_replace("--replace--",$source,$T_lang['func'][8]);
return $errors;
}else{
if($source==$T_Recycled){//清空回收站时 这个判断条件用的上
return "";
}else{
if(@rmdir($source)){
return "";
}else{
$errors .= str_replace("--replace--",$source,$T_lang['func'][8]);
return $errors;
}
}
}
}
function limitname($title,$limitlength =13){//限制标题长度
$length = strlen($title);
if($length>$limitlength){
$gbk = 0;
for($i=0;$i<$limitlength-1;$i++){
$temp = substr($title,$i,1);
if(ord($temp)>127) $gbk +=1;
}
if($gbk%2){
$title = substr($title,0,$limitlength)."...";
}else{
$title = substr($title,0,$limitlength-1)."...";
}
}
return $title;
}
function fileext($filename){
return trim(substr(strrchr($filename, '.'), 1));
}
function checkpath($path){//检查path合法和合格性
$path = eregi_replace("root",".",$path);
if($path=="."||ereg("^(\.\/).*[^\.\/]$",$path)){
if(eregi("\.\/(.*)?(\.\.\/)+.",$path)){
return false;
}else{
if(is_dir($path)){
return $path;
}else{
return false;
}
}
}else{
return false;
}
}
function historypath(){//历史路径
global $path,$T_rlength,$T_images,$T_main,$T_Recycled;
$ruote = explode("/",$path);
$num = count($ruote);
if($num<=1){
return false;
}else{
if($num-1>$T_rlength){
$i = $num-$T_rlength;
}else{
$i = 1;
}
for(;$i<=$num-1;$i++){
$rs .= "<img src={$T_images}/direct.gif align=absmiddle><a href=\"{$T_main}?path=";
$single = ".";
for($j=1;$j<=$i;$j++){
$single .= "/".$ruote[$j];
}
$rs .= urlencode($single)."\"><img src=\"";
if($single==$T_Recycled){
$rs .= $T_images."/Recycled.gif";
}else{
$rs .= $T_images."/folder.gif";
}
$rs .= "\" height=\"50\" width=\"50\" align=absmiddle>".limitname($ruote[$i])."</a>";
}
return $rs;
}
}
?>
<?php
/**
*
* 计数器(v1.1.0)
*
* Version : 1.1.0
* Author : 村长
* PHP : >4.3
*
*/
class Counter
{
var $CountFolder;
var $countType;
var $showtype;
var $imgArray;
function Counter()
{
$this->countType = 0;
$this->showtype = "GetCountByDay";
$this->imgArray = array();
$this->MakeCounter();
}
function MakeCounter()
{
$this->CountFolder = "log/".date("Ymd");
if(!is_dir($this->CountFolder))
{
mkdir($this->CountFolder,0777);
}
$this->_DoCount();
}
//Save data file
function _DoCount()
{
$file = date("Ymd").ip2long($_SERVER['REMOTE_ADDR']).".txt";
if(!file_exists($this->CountFolder."/".$file))
{
$fp = @fopen($this->CountFolder."/".$file,"wb+");
//这里可以保存其他需要的日志记录
@fputs($fp,$_SERVER['REMOTE_ADDR']);
@fclose($fp);
}
}
//获得指定时间的统计数据
//默认为1天 0 为取所有
function GetCountByDay($day=1)
{
//今日的时间戳
$today = strtotime(date("Y-m-d"));
$all = 0;
for($i=$day;$i>=0;$i--)
{
$tsp = $today-(86400*$i);
$folder = "log/".date("Ymd",$tsp)."/*.txt";
$ta = glob("$folder");
$all= $all+ count($ta);
}
return $all;
}
function GetCountUseImg($day=1)
{
$allnumber = $this->GetCountByDay($day);
for($i=0;$i<strlen($allnumber);$i++)
{
$idx = substr($allnumber,$i,1);
$returnVal.= sprintf("<img src=\"%s\">",$this->imgArray[$idx]);
}
return $returnVal;
}
function SetStyle($style='',$ext="gif")
{
$imgprefix ="img/";
$folder = $imgprefix.$style;
foreach(range(0,9) as $num)
{
$this->imgArray[$num] = $folder."/".$num.".$ext";
}
if(is_dir($folder))
{
$this->showtype = "GetCountUseImg";
}
else
{
$this->showtype = "GetCountByDay";
}
}
function Show($day=0)
{
return $this->{$this->showtype}($day);
}
}
//实例计数器对象
$counter = new Counter();
//采用 sports98 样式显示,告知默认扩展名为png格式
$counter->SetStyle("sports98","png");
echo "<br />今日访问:".$counter->Show(0);
//采用S1样式显示,默认扩展名为 gif
$counter->SetStyle("s1");
echo "<br />近3日访问:".$counter->Show(2);
//----只显示文字的计数器
$counter->SetStyle("-");
echo "<br />近3日访问:".$counter->Show(2);
?>
#*********************************************************
#文件名称: function.php
#功能描述: 新闻添加修改处理模块
#程序制作:留印(adleyliu)
#联系qq :14339095
#联系邮箱:[email=adleyliu@163.com]adleyliu@163.com[/email]
#官方网站: [url=http://www.115000.com.cn]http://www.115000.com.cn[/url]
#copyright (c) 2007-2008 115000.com.cn all rights reserved.
#最后更新: 2007-11-20
#*********************************************************
#*********************************************************
#分页函数
#*********************************************************
function yl_list_page($pageurl,$rsnum,$pages,$pagecount,$pagesize){
#url
#总记录
#总页数
#当前页码
#每页显示数
//$pageurl='?';
$pcount = $pages;
$page_info = '<div class=pagenum>';
$page_info .= '<div class=num>';
if (($pcount > 1) && ($pcount == $pagecount) ){
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount-1).'>上一页</a>';
}elseif (($pagecount != 1) && ($pcount != $pagecount)){
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount-1).'>上一页</a>';
}
$page_info .= '<a href = '.$pageurl.'page=1>页首</a>';
if ($pagecount > 4){
$page_info .= '<a href = '.$pageurl.'page=1>[1]</a><span class=dot>...</span>';
}
if ($pcount > $pagecount+2){
$endpage = $pagecount+2;
}else{
$endpage = $pcount;
}
for ($n = ($pagecount-2); $n <= $endpage; $n++){
if (!($n < 1)){
if ($n == intval($pagecount)){
$page_info .= '<span class=normal>'.$n.'</span>';
}else{
$page_info .= '<a href = '.$pageurl.'page='.$n.'>['.$n.']</a>';
}
}
}
if ($pagecount+2 < $pcount){
$page_info .= '<span class=dot>...</span><a href='.$pageurl.'page='.$pcount.'>['.$pcount.']</a>';
}
$page_info .= '<a href = '.$pageurl.'page='.$pcount.'>页尾</a>';
if (($pagecount == 1) && ($pcount != $pagecount) && ($pcount != 0)){
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount + 1).'>下一页</a>';
}else if (($pagecount != 1) && ($pcount != $pagecount)){
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount + 1).'>下一页</a>';
}
$page_info .= '</div></div>';
$page_info .= '<div class=pagenum>';
$page_info .= '<div class=num><span class=normal> 共:'.$rsnum .'条/'.$pcount.'页 每页/'.$pagesize.'条</span></div>';
$page_info .= ' <div class=num>';
//echo '<form name=page action='.$pageurl.'>';
$page_info .= ' 转到';
$page_info .= '<input type=text name=page value=\'1\' class=login_left style=\'width:28px;height:18px;\'>';
$page_info .= '页<input type=submit name=submit3 class=login_submit style=\'width:28px;height:18px;padding-top:1px;\' onclick=document.myform.action.value=\'go\'> ';
//echo '</form>';
$page_info .= '</div>';
$page_info .= '</div>';
return $page_info;
}
相关文章
- eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
- 在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
Python astype(np.float)函数使用方法解析
这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08- 这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
- 本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
- 下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 本篇文章主要是对c#中数据类型占用的字节数进行了详细的介绍。需要的朋友可以过来参考下,希望对大家有所帮助...2020-06-25
- CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
- 这篇文章主要给大家介绍了关于Nest.js参数校验和自定义返回数据格式的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-28
Android开发中findViewById()函数用法与简化
findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20- 这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
- strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
- 这篇文章主要介绍了C#中decimal保留2位有效小数的实现方法,针对decimal变量保留2位有效小数有多种方法,可以使用Math.Round方法以及ToString先转换为字符串等操作来实现。具体实现方法感兴趣的朋友跟随小编一起看看吧...2020-06-25
PHP函数分享之curl方式取得数据、模拟登陆、POST数据
废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07- Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
- free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
- 这篇文章主要介绍了解决Springboot get请求是参数过长的情况,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-17
- 本篇文章主要是对C#中获取目前月份的天数的三种方法进行了详细的总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助...2020-06-25
- 今天小编就为大家分享一篇Pandas实现DataFrame按行求百分数(比例数),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-05-09
PHP中empty和isset对于参数结构的判断及empty()和isset()的区别
废话不多说了,直接给大家贴代码了。<?php class test{} $a1 = null; $a2 = ""; //$a3 = $a4 = 0; $a5 = '0'; $a6 = false; $a7 = array(); //var $a8; $a9 = new test(); for ($i=1; $i <=9 ; $i++) {...2015-11-24