php获取网页内容

 更新时间:2016年11月25日 16:13  点击:2056

1。使用xmlhttp对象,类似于asp中的ActiveXObject对象,其实xmlhttp无非就是get和put的操作,在php里面

get的,直接用file_get_contents/fopen/readfile这些函数就是了

put的,自己写fsockopen发送也行,用NET_Curl也行

(直接用系统函数要简单,通用,耗费资源少)

$xhr = new COM("MSXML2.XMLHTTP");
$xhr->open("GET","http://localhost/xxx.php?id=2",false);
$xhr->send();
echo $xhr->responseText

2。上面说的file_get_contents实现

<?php
$url="http://www.blogjava.net/pts";
echo file_get_contents( $url );
?>

3。上面说的fopen()实现

<?
if ($stream = fopen('http://www.sohu.com', 'r')) {
    // print all the page starting at the offset 10
    echo stream_get_contents($stream, -1, 10);
    fclose($stream);
}

if ($stream = fopen('http://www.sohu.net', 'r')) {
    // print the first 5 bytes
    echo stream_get_contents($stream, 5);
    fclose($stream);
}
?>

对比起 Cookie,Session 是存储在服务器端的会话,相对安全,并且不像 Cookie 那样有存储长度限制,本文简单介绍 Session 的使用。

  由于 Session 是以文本文件形式存储在服务器端的,所以不怕客户端修改 Session 内容。实际上在服务器端的 Session 文件,PHP 自动修改 Session 文件的权限,只保留了系统读和写权限,而且不能通过 ftp 修改,所以安全得多。

  对于 Cookie 来说,假设我们要验证用户是否登陆,就必须在 Cookie 中保存用户名和密码(可能是 md5 加密后字符串),并在每次请求页面的时候进行验证。如果用户名和密码存储在数据库,每次都要执行一次数据库查询,给数据库造成多余的负担。因为我们并不能只做一次验证。为什么呢?因为客户端 Cookie 中的信息是有可能被修改的。假如你存储 $admin 变量来表示用户是否登陆,$admin 为 true 的时候表示登陆,为 false 的时候表示未登录,在第一次通过验证后将 $admin 等于 true 存储在 Cookie,下次就不用验证了,这样对么?错了,假如有人伪造一个值为 true 的 $admin 变量那不是就立即取的了管理权限么?非常的不安全。

  而 Session 就不同了,Session 是存储在服务器端的,远程用户没办法修改 Session 文件的内容,因此我们可以单纯存储一个 $admin 变量来判断是否登陆,首次验证通过后设置 $admin 值为 true,以后判断该值是否为 true,假如不是,转入登陆界面,这样就可以减少很多数据库操作了。而且可以减少每次为了验证 Cookie 而传递密码的不安全性了(Session 验证只需要传递一次,假如你没有使用 SSL 安全协议的话)。即使密码进行了 md5 加密,也是很容易被截获的。

  当然使用 Session 还有很多优点,比如控制容易,可以按照用户自定义存储等(存储于数据库)。我这里就不多说了。

  Session 在 php.ini 是否需要设置呢?一般不需要的,因为并不是每个人都有修改 php.ini 的权限,默认 Session 的存放路径是服务器的系统临时文件夹,我们可以自定义存放在自己的文件夹里,这个稍后我会介绍。

  开始介绍如何创建 Session。非常简单,真的。

  启动 Session 会话,并创建一个 $admin 变量:

<?php
    
//  启动 Session
    
session_start
();
    
//  声明一个名为 admin 的变量,并赋空值。
    
$_SESSION["admin"] = null
;
?>

  如果你使用了 Seesion,或者该 PHP 文件要调用 Session 变量,那么就必须在调用 Session 之前启动它,使用 session_start() 函数。其它都不需要你设置了,PHP 自动完成 Session 文件的创建。

  执行完这个程序后,我们可以到系统临时文件夹找到这个 Session 文件,一般文件名形如:sess_4c83638b3b0dbf65583181c2f89168ec,后面是 32 位编码后的随机字符串。用编辑器打开它,看一下它的内容:

admin|N;

一般该内容是这样的结构:

变量名|类型:长度:值;

并用分号隔开每个变量。有些是可以省略的,比如长度和类型。

  我们来看一下验证程序,假设数据库存储的是用户名和 md5 加密后的密码:

login.php

<?php

    
//  表单提交后...
    
$posts = $_POST
;
    
//  清除一些空白符号
    
foreach ($posts as $key => $value
)
    {
        
$posts[$key] = trim($value
);
    }
    
$password = md5($posts["password"
]);
    
$username = $posts["username"
];

    
$query = "SELECT `username` FROM `user` WHERE `password` = '$password'"
;
    
//  取得查询结果
    
$userInfo = $DB->getRow($query
);

    if (!empty(
$userInfo
))
    {
        if (
$userInfo["username"] == $username
)
        {
            
//  当验证通过后,启动 Session
            
session_start
();
            
//  注册登陆成功的 admin 变量,并赋值 true
            
$_SESSION["admin"] = true
;
        }
        else
        {
            die(
"用户名密码错误"
);
        }
    }
    else
    {
        die(
"用户名密码错误"
);
    }

?>

  我们在需要用户验证的页面启动 Session,判断是否登陆:

<?php

    
//  防止全局变量造成安全隐患
    
$admin = false
;

    
//  启动会话,这步必不可少
    
session_start
();

    
//  判断是否登陆
    
if (isset($_SESSION["admin"]) && $_SESSION["admin"] === true
)
    {
        echo
"您已经成功登陆"
;
    }
    else
    {
        
//  验证失败,将 $_SESSION["admin"] 置为 false
        
$_SESSION["admin"] = false
;
        die(
"您无权访问"
);
    }

?>

  是不是很简单呢?将 $_SESSION 看成是存储在服务器端的数组即可,我们注册的每一个变量都是数组的键,跟使用数组没有什么分别。

  如果要登出系统怎么办?销毁 Session 即可。

<?php

    session_start
();
    
//  这种方法是将原来注册的某个变量销毁
    
unset($_SESSION["admin"
]);

    
//  这种方法是销毁整个 Session 文件
    
session_destroy
();

?>

  Session 能否像 Cookie 那样设置生存周期呢?有了 Session 是否就完全抛弃 Cookie 呢?我想说,结合 Cookie 来使用 Session 才是最方便的。

  Session 是如何来判断客户端用户的呢?它是通过 Session ID 来判断的,什么是 Session ID,就是那个 Session 文件的文件名,Session ID 是随机生成的,因此能保证唯一性和随机性,确保 Session 的安全。一般如果没有设置 Session 的生存周期,则 Session ID 存储在内存中,关闭浏览器后该 ID 自动注销,重新请求该页面后,重新注册一个 Session ID。

  如果客户端没有禁用 Cookie,则 Cookie 在启动 Session 会话的时候扮演的是存储 Session ID 和 Session 生存期的角色。

  我们来手动设置 Session 的生存期:

<?php 

    session_start(); 
    
//  保存一天
    
$lifeTime = 24 * 3600
;
    
setcookie(session_name(), session_id(), time() + $lifeTime, "/"); 

?>

  其实 Session 还提供了一个函数 session_set_cookie_params(); 来设置 Session 的生存期的,该函数必须在 session_start() 函数调用之前调用:

<?php 

    
//  保存一天
    
$lifeTime = 24 * 3600
;
    
session_set_cookie_params($lifeTime
);
    
session_start
();
    
$_SESSION["admin"] = true
;

?>

 

  如果客户端使用 IE 6.0 , session_set_cookie_params(); 函数设置 Cookie 会有些问题,所以我们还是手动调用 setcookie 函数来创建 cookie。

  假设客户端禁用 Cookie 怎么办?没办法,所有生存周期都是浏览器进程了,只要关闭浏览器,再次请求页面又得重新注册 Session。那么怎么传递 Session ID 呢?通过 URL 或者通过隐藏表单来传递,PHP 会自动将 Session ID 发送到 URL 上,URL 形如:http://www.openphp.cn/index.php?PHPSESSID=bba5b2a240a77e5b44cfa01d49cf9669,其中 URL 中的参数 PHPSESSID 就是 Session ID了,我们可以使用 $_GET 来获取该值,从而实现 Session ID 页面间传递。

<?php 

    
//  保存一天
    
$lifeTime = 24 * 3600
;
    
//  取得当前 Session 名,默认为 PHPSESSID
    
$sessionName = session_name
();
    
//  取得 Session ID
    
$sessionID = $_GET[$sessionName
];
    
//  使用 session_id() 设置获得的 Session ID
    
session_id($sessionID
); 

    
session_set_cookie_params($lifeTime);
    
session_start
();
    
$_SESSION["admin"] = true
;

?>

  对于虚拟主机来说,如果所有用户的 Session 都保存在系统临时文件夹里,将给维护造成困难,而且降低了安全性,我们可以手动设置 Session 文件的保存路径,session_save_path()就提供了这样一个功能。我们可以将 Session 存放目录指向一个不能通过 Web 方式访问的文件夹,当然,该文件夹必须具备可读写属性。

<?php 

    
//  设置一个存放目录
    
$savePath = "./session_save_dir/"
;
    
//  保存一天
    
$lifeTime = 24 * 3600
;
    
session_save_path($savePath
);
    
session_set_cookie_params($lifeTime
);
    
session_start
();
    
$_SESSION["admin"] = true
;

?>

  同 session_set_cookie_params(); 函数一样,session_save_path() 函数也必须在 session_start() 函数调用之前调用。

  我们还可以将数组,对象存储在 Session 中。操作数组和操作一般变量没有什么区别,而保存对象的话,PHP 会自动对对象进行序列化(也叫串行化),然后保存于 Session 中。下面例子说明了这一点:

person.php

<?php
    
class
person
    
{
        var
$age
;
        function
output
() {
            echo
$this->age
;
        }
     
        function
setAge($age
) {
            
$this->age = $age
;
        }
    }
?>

setage.php

<?php

    session_start
();
    require_once
"person.php"
;
    
$person = new person
();
    
$person->setAge(21
);
    
$_SESSION['person'] = $person
;
    echo
"<a href='output'>check here to output age</a>"
;

?>

output.php

<?

    
// 设置回调函数,确保重新构建对象。
    
ini_set('unserialize_callback_func', 'mycallback'
);
    function
mycallback($classname
) {
        include_once
$classname . ".php"
;
    }
    
session_start(); 

    
$person = $_SESSION["person"];
    
//  输出 21
    
$person->output
();

?>

  当我们执行 setage.php 文件的时候,调用了 setage() 方法,设置了年龄为 21,并将该状态序列化后保存在 Session 中(PHP 将自动完成这一转换),当转到 output.php 后,要输出这个值,就必须反序列化刚才保存的对象,又因为在解序列化的时候需要实例化一个未定义类,所以我们定义了以后回调函数,自动包含 person.php 这个类文件,因此对象被重构,并取得当前 age 的值为 21,然后调用 output() 方法输出该值。

  另外,我们还可以使用 session_set_save_handler 函数来自定义 Session 的调用方式。

  认识水平有限,本文难免有错误之处,敬请指正。


<?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 || $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
/*******************************************
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
/*
--------------------------
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;
 }
}
?>

[!--infotagslink--]

相关文章

  • PHP成员变量获取对比(类成员变量)

    下面本文章来给大家介绍在php中成员变量的一些对比了,文章举了四个例子在这例子中分别对不同成员变量进行测试与获取操作,下面一起来看看。 有如下4个代码示例,你认...2016-11-25
  • php 获取用户IP与IE信息程序

    php 获取用户IP与IE信息程序 function onlineip() { global $_SERVER; if(getenv('HTTP_CLIENT_IP')) { $onlineip = getenv('HTTP_CLIENT_IP');...2016-11-25
  • php获取一个文件夹的mtime的程序

    php获取一个文件夹的mtime的程序了,这个就是时间问题了,对于这个问题我们来看小编整理的几个例子,具体的操作例子如下所示。 php很容易获取到一个文件夹的mtime,可以...2016-11-25
  • 如何获取网站icon有哪些可行的方法

    获取网站icon,常用最简单的方法就是通过website/favicon.ico来获取,不过由于很多网站都是在页面里面设置favicon,所以此方法很多情况都不可用。 更好的办法是通过google提供的服务来实现:http://www.google.com/s2/favi...2014-06-07
  • jquery如何获取元素的滚动条高度等实现代码

    主要功能:获取浏览器显示区域(可视区域)的高度 : $(window).height(); 获取浏览器显示区域(可视区域)的宽度 :$(window).width(); 获取页面的文档高度 $(document).height(); 获取页面的文档宽度 :$(document).width();...2015-10-21
  • jquery获取div距离窗口和父级dv的距离示例

    jquery中jquery.offset().top / left用于获取div距离窗口的距离,jquery.position().top / left 用于获取距离父级div的距离(必须是绝对定位的div)。 (1)先介绍jquery.offset().top / left css: 复制代码 代码如下: *{ mar...2013-10-13
  • Jquery 获取指定标签的对象及属性的设置与移除

    1、先讲讲JQuery的概念,JQuery首先是由一个 America 的叫什么 John Resig的人创建的,后来又很多的JS高手也加入了这个团队。其实 JQuery是一个JavaScript的类库,这个类库集合了很多功能方法,利用类库你可以用简单的一些代...2014-05-31
  • php根据用户语言跳转相应网页

    当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。 <&#63;php $lan = substr(&#8194;$HTTP_ACCEPT_LANGUAGE,0,5); if ($lan == "zh-cn") print("<meta http-equiv='refresh' c...2015-11-08
  • C#获取字符串后几位数的方法

    这篇文章主要介绍了C#获取字符串后几位数的方法,实例分析了C#操作字符串的技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • jquery获取tagName再进行判断

    如果是为了取到tagName后再进行判断,那直接用下面的代码会更方便: $(element).is('input') 如果是要取到标签用作到别的地方,可以使用一下代码: $(element)[0].tagName 或: $(element).get(0).tagName...2014-05-31
  • DOM XPATH获取img src值的query

    复制代码 代码如下:$nodes = @$xpath->query("//*[@id='main_pr']/img/@src");$prurl = $nodes->item(0)->nodeValue;...2013-10-04
  • 腾讯视频怎么放到自己的网页上?

    腾讯视频怎么放到自己的网页上?这个问题是一个基本的问题,要把腾讯视频放到自己的网页有许多的办法,当然一般情况就是直接使用它们的网页代码了,如果你要下载资源再放到...2016-09-20
  • PHP 如何获取二维数组中某个key的集合

    本文为代码分享,也是在工作中看到一些“大牛”的代码,做做分享。 具体是这样的,如下一个二维数组,是从库中读取出来的。 代码清单: 复制代码 代码如下: $user = array( 0 => array( 'id' => 1, 'name' => '张三', 'ema...2014-06-07
  • php获取汉字拼音首字母的方法

    现实中我们经常看到这样的说明,排名不分先后,按姓名首字母进行排序。这是中国人大多数使用的排序方法。那么在php程序中该如何操作呢?下面就分享一下在php程序中获取汉字拼音的首字母的方法,在网上搜到的大多数是有问题的...2015-10-23
  • 基于JavaScript实现网页倒计时自动跳转代码

    这篇文章主要介绍了基于JavaScript实现网页倒计时自动跳转代码 的相关资料,需要的朋友可以参考下...2015-12-29
  • 使用C#获取系统特殊文件夹路径的解决方法

    本篇文章是对使用C#获取系统特殊文件夹路径的解决方法进行了详细的分析介绍,需要的朋友参考下...2020-06-25
  • php如何获取文件的扩展名

    网上也有很多类似的方法,不过都存在这样那样的不严谨的问题,本文就不一一分析了,这里只给出最正确的利用php 获取文件扩展名(文件后缀名)的方法。 function get_extension($filename){ return pathinfo($filename,PATHIN...2015-10-30
  • 网页头部声明lang=”zh-cn”、lang=“zh”、lang=“zh-cmn-Hans”区别

    我们现在使用的软件都会自动在前面加一个申明了,那么在网页头部声明lang=”zh-cn”、lang=“zh”、lang=“zh-cmn-Hans”区别是什么呢?下面我们就一起来看看吧. 单...2016-09-20
  • 基于JavaScript获取鼠标位置的各种方法

    这篇文章主要介绍了基于JavaScript获取鼠标位置的各种方法 ,需要的朋友可以参考下...2015-12-18
  • C#获取变更过的DataTable记录的实现方法

    这篇文章主要介绍了C#获取变更过的DataTable记录的实现方法,对初学者很有学习借鉴价值,需要的朋友可以参考下...2020-06-25