类似dz 分页代码
用法示例:
<?php
Class_Scroll::_Print($_SERVER['PHP_SELF'],1234,$_GET['Page'],10,$_SERVER['QUERY_STRING'],"Page",9,true);
?>
<?php
/**
* 实现滚动栏的类
*
* 根据页面内容,数据量,生成一个用来显示/控制的页面滚动栏.
* <code>
* Class_Scroll::_Print($_SERVER['PHP_SELF'],1234,$_GET['Page'],10,$_SERVER['QUERY_STRING'],"Page",9,true);
* </code>
*
* @author 周贝晨 2006-7-16
* @version 2.1
*
* @todo 生成一个页面内容滚动栏
*/
class Class_Scroll{
/**
* 输出页面滚动栏
*
* @param string $AScriptName 要进行滚动的页面
* @param integer $ATotalCount 滚动信息的总数
* @param integer $ANowPageID 当前页号
* @param integer $AInnerCount 每页内的信息数
* @param string $AVar 需要附带的其它变量及其值
* @param string $APageKey 用来指定页号的变量名
* @param integer $APageBundle 滚动栏显示的页数批示最大值
* @param boolean $IncJump 是否显示页面跳转下拉单(默认:true)
* @return string 页面滚动栏的HTML代码
*/
function _Print($AScriptName,$ATotalCount,$ANowPageID,$AInnerCount,$AVar,$APageKey="Page",$APageBundle=9,$IncJump = true){
// 没有项目
if( $ATotalCount == 0 or $ATotalCount == "") return "没有相关内容.";//"No Item Here.";
// 计算总页数
$PageCount = ceil($ATotalCount / $AInnerCount);
// 检查控制当前页码值
if($ANowPageID < 1) $ANowPageID = 1;
if($ANowPageID > $PageCount) $ANowPageID = $PageCount;
// 确定当然要显示的数码链接值
$StartNum = ($ANowPageID - floor($APageBundle / 2)) > 0 ? ($ANowPageID - floor($APageBundle / 2)) : 1;
$EndNum = ($PageCount - $StartNum) < $APageBundle ? $PageCount : ($StartNum + $APageBundle - 1);
if((($EndNum - $StartNum) < $APageBundle)&&($PageCount > $APageBundle)) $StartNum = $EndNum - $APageBundle + 1;
// 获得变量
if(strlen($AVar) > 0) $Vars = explode("&",$AVar);
if(count($Vars) > 0){
for($i=0;$i<count($Vars);$i++){
$v = explode("=",$Vars[$i]);
if($v[0]!=$APageKey) $VarString.=sprintf("%s=%s&",$v[0],$v[1]);
}
}
// 首页链接
$OutStringr = sprintf('<a href="%s?%s%s=%s">%s</a>%s',$AScriptName,$VarString,$APageKey,"1","首页","r");
// 上一页链接
$OutStringr .= ($ANowPageID==1) ? " " : sprintf('<a href="%s?%s%s=%s">%s</a>%s',$AScriptName,$VarString,$APageKey,$ANowPageID-1,"上一页","r");
// 中间页链接
for($i = $StartNum; $i <= $EndNum; $i++)
$OutStringr .= ($i==$ANowPageID) ? sprintf("<span class="Currpage">%s</span>%s",$i,"r") : sprintf('<a href="%s?%s%s=%s">%s</a>%s',$AScriptName,$VarString,$APageKey,$i,$i,"r");
// 下一页链接
$OutStringr .= ($ANowPageID==$PageCount) ? " " : sprintf('<a href="%s?%s%s=%s">%s</a>%s',$AScriptName,$VarString,$APageKey,$ANowPageID+1,"下一页","r");
// 尾页链接
$OutStringr .= sprintf('<a href="%s?%s%s=%s">%s</a> 共%s页%s条%s',$AScriptName,$VarString,$APageKey,$PageCount,"尾页",$PageCount,$ATotalCount,"r");
// 跳转链接
if ($IncJump){
$OutStringr .= sprintf("<label>跳至(J): <select name="ScrollJump" accesskey="j" onChange="javascript:if(this.value != 0) document.location='%s?%s%s='+this.value;" id="ScrollJump">%s",$$AScriptName,$VarString,$APageKey,"r");
for($i = 1; $i <= $PageCount; $i++) {
$SelectedStr = ($i == $ANowPageID) ? " selected="selected"" : "";
$OutStringr .= sprintf("<option value="%d"%s>第%d页</option>%s",$i,$SelectedStr,$i,"r");
}
$OutStringr .= "</select></label>";
}
// 输出
return $OutStringr;
}
}
?>
我发现很多的PHP程序员,尤其是学习还不是很久的,都不知道PHP的精华所在。Perl当年如何在商界出名?其强大的正则表达式。而PHP呢?他是一门从Unix下发展起来的语言,当然也就继续了Perl的很多特点,同时C的优点都有。快速、简洁、明了,尤其是C程序员,PHP是至爱,我就是深爱着“PHP”(都忘了女友了:))。这里,我想来写一篇PHP的变量、数组应用技巧和PHP的正则表达式、PHP的模板应用,以后有时间再写PHP与COM、PHP与XML的完全结合。
1、变量、数组的应用技巧
(1)很多人用得不多的数组函数。foreach、list、each。分别举几个例子,应该就能知道了。例:
<?php
$data = array('a' => 'data1', 'b' => 'data2', 'c' => 'data3');
while(list($subscript, $value) = each($data))
{
echo "$subscript => $value :: ";
echo "$subscript => $value <br>";
}
reset($data);
foreach($data as $subscript => $value)
{
echo "$subscript => $value :: ";
echo "$subscript => $value <br>";
}
(2)函数的变量、变量的变量、变量的“指针”:看下例:
<?php
//变量的变量
$var = "this is a var";
$varname = "var";
echo $$varname;
//函数的变量
function fun1($str) {
echo $str;
}
$funname = "fun1";
$funname("This is a function !");
?>
变量的“指针”。这个指针加上了双引号,表明他不是真正的指针。看看下例:
<?php
function($a) {
$a ;
}
$c = 0;
function($c);
echo $c; //$c仍为0
function(&$a) {
$a ;
}
$c = 0;
echo $c; //$c为1
?>
之所以称其为“指针”,就是因为他有了和C语言中指针相同的功能。但这又不是真正的指针,只能够是这样的去理解。
2、正则表达式
正则表达式是一个非常大的题目,Perl的正则表达式的强大是闻了名的。而PHP也不弱,他继续了Perl的正则表达式法则,还有自己的一套法则。这里只说PHP自己的正则表达式。
正则表达式是最基本的元素。简单地说就是一套规则,用于去判定其它的元素是不是符合自身的规则,或者说是不是有相同的特征描述。
正则表达式的开始符:^,结尾符$,这两个符号间的是匹配的元素。如检查一个电话号码是不是打往北京的号,用正则表达式表示就是“^010$”。只要前3位区号是010,就是北京的号,后面的电话号码就不用管了。然后,用正则表达式匹配函数ereg来判定,例:
<?php
$pattern = "^010$";
$phone = "01080718828";
if(ereg($pattern, $phone))
echo "打往北京的号";
else
echo "不是打往北京的号";
?>
这就是正则表达式。北京的电话都是8位数字的,那我要知道这个号码是不是正确了?假如他按了9位号呢?假如判定正误?这就要用到正则表达式的字符簇。那么上例的正则表达式就要这样写:^010[0-9]{8}$,就能同时判定号码是不是符合规则。正则表达式有很多的应用,像LBB、VBB论坛在发贴时的所谓VBB代码LBB代码的解析,都是用正则表达式完成的。
3、模板
知道了正则表达式的功能,那么就可以知道模板了。什么是模板?举个例子吧?一般写网页用到了后台程序的时候,都是在网页里面插入程序代码。如PHP。这就是HTML和PHP的混写。这样的优点是读取速度快,缺点是假如大家分工合作做网站,那么非程序员就不会改网了。
而用模板,则可以达到分工的最合理化。美工只做页面,程序只写后台,然后再合起来。优秀的Jsp提供了自定义标签的功能很好地完成了模板功能。而主流的PHP如何做到呢?就是利用正则表达式来做到的。可以去网上下载一个PHPLIB,里面的PHP目录下有一个template.inc的源代码文件,那就是用PHP实现模板套用的类。
由于篇幅有限,这里只是简单地说一说这些内容,假如真的想学的话,还请看专门的教材。如光要讲清楚正则表达式就可以写上一本小书。
先来看看,例子调用方法:
效果图:
下面来看看代码.先上传类?<?php
/*
TITLE : CLASS Upload
FILE : class.upload.php
DESCRIPTION : To provide upload utility,
AUTHOR : Peng Zhang zpadmin()gmail.com http://blog.neten.de
BASED ON : whxbb whxbb()21cn.com
WRITED : 2005 NOV 20
MODIFIED : 2006 MAR 01
modify by psdshow (psdshow(at)yahoo.com.cn) 2007-11-30
LICENCE : GPL
REVISION : V1.0.2
*/
class Upload{
var $saveName;// 保存名
var $savePath;// 保存路径
var $fileFormat = array('gif','jpg','doc','application/octet-stream');// 文件格式&MIME限定
var $overwrite = 0;// 覆盖模式
var $maxSize = 0;// 文件最大字节
var $ext;// 文件扩展名
var $thumb = 0;// 是否生成缩略图
var $thumbWidth = 130;// 缩略图宽
var $thumbHeight = 130;// 缩略图高
var $thumbPrefix = "_thumb_";// 缩略图前缀
var $errno;// 错误代号
var $returnArray= array();// 所有文件的返回信息
var $returninfo= array();// 每个文件返回信息
// 构造函数
// @param $savePath 文件保存路径
// @param $fileFormat 文件格式限制数组
// @param $maxSize 文件最大尺寸
// @param $overwriet 是否覆盖 1 允许覆盖 0 禁止覆盖
function Upload($savePath, $fileFormat='',$maxSize = 0, $overwrite = 0) {
$this->setSavepath($savePath);
$this->setFileformat($fileFormat);
$this->setMaxsize($maxSize);
$this->setOverwrite($overwrite);
$this->setThumb($this->thumb, $this->thumbWidth,$this->thumbHeight);
$this->errno = 0;
}
// 上传
// @param $fileInput 网页Form(表单)中input的名称
// @param $changeName 是否更改文件名
function run($fileInput,$changeName = 1){
if(isset($_FILES[$fileInput])){
$fileArr = $_FILES[$fileInput];
if(is_array($fileArr['name'])){//上传同文件域名称多个文件
for($i = 0; $i < count($fileArr['name']); $i++){
$ar['tmp_name'] = $fileArr['tmp_name'][$i];
$ar['name'] = $fileArr['name'][$i];
$ar['type'] = $fileArr['type'][$i];
$ar['size'] = $fileArr['size'][$i];
$ar['error'] = $fileArr['error'][$i];
$this->getExt($ar['name']);//取得扩展名,赋给$this->ext,下次循环会更新
$this->setSavename($changeName == 1 ? '' : $ar['name']);//设置保存文件名
if($this->copyfile($ar)){
$this->returnArray[] = $this->returninfo;
}else{
$this->returninfo['error'] = $this->errmsg();
$this->returnArray[] = $this->returninfo;
}
}
return $this->errno ? false : true;
}else{//上传单个文件
$this->getExt($fileArr['name']);//取得扩展名
$this->setSavename($changeName == 1 ? '' : $fileArr['name']);//设置保存文件名
if($this->copyfile($fileArr)){
$this->returnArray[] = $this->returninfo;
}else{
$this->returninfo['error'] = $this->errmsg();
$this->returnArray[] = $this->returninfo;
}
return $this->errno ? false : true;
}
return false;
}else{
$this->errno = 10;
return false;
}
}
// 单个文件上传
// @param $fileArray 文件信息数组
function copyfile($fileArray){
$this->returninfo = array();
// 返回信息
$this->returninfo['name'] = $fileArray['name'];
$this->returninfo['saveName'] = $this->saveName;
$this->returninfo['size'] = number_format( ($fileArray['size'])/1024 , 0, '.', ' ');//以KB为单位
$this->returninfo['type'] = $fileArray['type'];
// 检查文件格式
if (!$this->validateFormat()){
$this->errno = 11;
return false;
}
// 检查目录是否可写
if(!@is_writable($this->savePath)){
$this->errno = 12;
return false;
}
// 如果不允许覆盖,检查文件是否已经存在
//if($this->overwrite == 0 && @file_exists($this->savePath.$fileArray['name'])){
// $this->errno = 13;
// return false;
//}
// 如果有大小限制,检查文件是否超过限制
if ($this->maxSize != 0 ){
if ($fileArray["size"] > $this->maxSize){
$this->errno = 14;
return false;
}
}
// 文件上传
if(!@move_uploaded_file($fileArray["tmp_name"], $this->savePath.$this->saveName)){
$this->errno = $fileArray["error"];
return false;
}elseif( $this->thumb ){// 创建缩略图
$CreateFunction = "imagecreatefrom".($this->ext == 'jpg' ? 'jpeg' : $this->ext);
$SaveFunction = "image".($this->ext == 'jpg' ? 'jpeg' : $this->ext);
if (strtolower($CreateFunction) == "imagecreatefromgif"
&& !function_exists("imagecreatefromgif")) {
$this->errno = 16;
return false;
} elseif (strtolower($CreateFunction) == "imagecreatefromjpeg"
&& !function_exists("imagecreatefromjpeg")) {
$this->errno = 17;
return false;
} elseif (!function_exists($CreateFunction)) {
$this->errno = 18;
return false;
}
$Original = @$CreateFunction($this->savePath.$this->saveName);
if (!$Original) {$this->errno = 19; return false;}
$originalHeight = ImageSY($Original);
$originalWidth = ImageSX($Original);
$this->returninfo['originalHeight'] = $originalHeight;
$this->returninfo['originalWidth'] = $originalWidth;
/*
if (($originalHeight < $this->thumbHeight
&& $originalWidth < $this->thumbWidth)) {
// 如果比期望的缩略图小,那只Copy
move_uploaded_file($this->savePath.$this->saveName,
$this->savePath.$this->thumbPrefix.$this->saveName);
} else {
if( $originalWidth > $this->thumbWidth ){// 宽 > 设定宽度
$thumbWidth = $this->thumbWidth ;
$thumbHeight = $this->thumbWidth * ( $originalHeight / $originalWidth );
if($thumbHeight > $this->thumbHeight){// 高 > 设定高度
$thumbWidth = $this->thumbHeight * ( $thumbWidth / $thumbHeight );
$thumbHeight = $this->thumbHeight ;
}
}elseif( $originalHeight > $this->thumbHeight ){// 高 > 设定高度
$thumbHeight = $this->thumbHeight ;
$thumbWidth = $this->thumbHeight * ( $originalWidth / $originalHeight );
if($thumbWidth > $this->thumbWidth){// 宽 > 设定宽度
$thumbHeight = $this->thumbWidth * ( $thumbHeight / $thumbWidth );
$thumbWidth = $this->thumbWidth ;
}
}
*/
$radio=max(($originalWidth/$this->thumbWidth),($originalHeight/$this->thumbHeight));
$thumbWidth=(int)$originalWidth/$radio;
$thumbHeight=(int)$originalHeight/$radio;
if ($thumbWidth == 0) $thumbWidth = 1;
if ($thumbHeight == 0) $thumbHeight = 1;
$createdThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
if ( !$createdThumb ) {$this->errno = 20; return false;}
if ( !imagecopyresampled($createdThumb, $Original, 0, 0, 0, 0,
$thumbWidth, $thumbHeight, $originalWidth, $originalHeight) )
{$this->errno = 21; return false;}
if ( !$SaveFunction($createdThumb,
$this->savePath.$this->thumbPrefix.$this->saveName) )
{$this->errno = 22; return false;}
}
// 删除临时文件
/*
if(!@$this->del($fileArray["tmp_name"])){
return false;
}
*/
return true;
}
// 文件格式检查,MIME检测
function validateFormat(){
if(!is_array($this->fileFormat)
|| in_array(strtolower($this->ext), $this->fileFormat)
|| in_array(strtolower($this->returninfo['type']), $this->fileFormat) )
return true;
else
return false;
}
// 获取文件扩展名
// @param $fileName 上传文件的原文件名
function getExt($fileName){
$ext = explode(".", $fileName);
$ext = $ext[count($ext) - 1];
$this->ext = strtolower($ext);
}
// 设置上传文件的最大字节限制
// @param $maxSize 文件大小(bytes) 0:表示无限制
function setMaxsize($maxSize){
$this->maxSize = $maxSize;
}
// 设置文件格式限定
// @param $fileFormat 文件格式数组
function setFileformat($fileFormat){
if(is_array($fileFormat)){$this->fileFormat = $fileFormat ;}
}
// 设置覆盖模式
// @param overwrite 覆盖模式 1:允许覆盖 0:禁止覆盖
function setOverwrite($overwrite){
$this->overwrite = $overwrite;
}
// 设置保存路径
// @param $savePath 文件保存路径:以 "/" 结尾,若没有 "/",则补上
function setSavepath($savePath){
$this->savePath = substr( str_replace("\\","/", $savePath) , -1) == "/"
? $savePath : $savePath."/";
}
// 设置缩略图
// @param $thumb = 1 产生缩略图 $thumbWidth,$thumbHeight 是缩略图的宽和高
function setThumb($thumb, $thumbWidth = 0,$thumbHeight = 0){
$this->thumb = $thumb;
if($thumbWidth) $this->thumbWidth = $thumbWidth;
if($thumbHeight) $this->thumbHeight = $thumbHeight;
}
// 设置文件保存名
// @param $saveName 保存名,如果为空,则系统自动生成一个随机的文件名
function setSavename($saveName){
if ($saveName == ''){ // 如果未设置文件名,则生成一个随机文件名
$name = date('YmdHis')."_".rand(100,999).'.'.$this->ext;
//判断文件是否存在,不允许重复文件
if(file_exists($this->savePath . $name)){
$name = setSavename($saveName);
}
} else {
$name = $saveName;
}
$this->saveName = $name;
}
// 删除文件
// @param $fileName 所要删除的文件名
function del($fileName){
if(!@unlink($fileName)){
$this->errno = 15;
return false;
}
return true;
}
// 返回上传文件的信息
function getInfo(){
return $this->returnArray;
}
// 得到错误信息
function errmsg(){
$uploadClassError = array(
0 =>'There is no error, the file uploaded with success. ',
1 =>'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
2 =>'The uploaded file exceeds the MAX_FILE_SIZE that was specified in the HTML form.',
3 =>'The uploaded file was only partially uploaded. ',
4 =>'No file was uploaded. ',
6 =>'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. ',
7 =>'Failed to write file to disk. Introduced in PHP 5.1.0. ',
10 =>'Input name is not unavailable!',
11 =>'The uploaded file is Unallowable!',
12 =>'Directory unwritable!',
13 =>'File exist already!',
14 =>'File is too big!',
15 =>'Delete file unsuccessfully!',
16 =>'Your version of PHP does not appear to have GIF thumbnailing support.',
17 =>'Your version of PHP does not appear to have JPEG thumbnailing support.',
18 =>'Your version of PHP does not appear to have pictures thumbnailing support.',
19 =>'An error occurred while attempting to copy the source image .
Your version of php ('.phpversion().') may not have this image type support.',
20 =>'An error occurred while attempting to create a new image.',
21 =>'An error occurred while copying the source image to the thumbnail image.',
22 =>'An error occurred while saving the thumbnail image to the filesystem.
Are you sure that PHP has been configured with both read and write access on this folder?',
);
if ($this->errno == 0)
return false;
else
return $uploadClassError[$this->errno];
}
}
?>
下面看看是怎么调用 的.:
<?php
//如果收到表单传来的参数,则进行上传处理,否则显示表单
if(isset($_FILES['uploadinput'])){
//建目录函数,其中参数$directoryName最后没有"/",
//要是有的话,以'/'打散为数组的时候,最后将会出现一个空值
function makeDirectory($directoryName) {
$directoryName = str_replace("\\","/",$directoryName);
$dirNames = explode('/', $directoryName);
$total = count($dirNames) ;
$temp = '';
for($i=0; $i<$total; $i++) {
$temp .= $dirNames[$i].'/';
if (!is_dir($temp)) {
$oldmask = umask(0);
if (!mkdir($temp, 0777)) exit("不能建立目录 $temp");
umask($oldmask);
}
}
return true;
}
if($_FILES['uploadinput']['name'] <> ""){
//包含上传文件类
require_once ('class.upload.php');
//设置文件上传目录
$savePath = "upload";
//创建目录
makeDirectory($savePath);
//允许的文件类型
$fileFormat = array('gif','jpg','jpge','png');
//文件大小限制,单位: Byte,1KB = 1000 Byte
//0 表示无限制,但受php.ini中upload_max_filesize设置影响
$maxSize = 0;
//覆盖原有文件吗? 0 不允许 1 允许
$overwrite = 0;
//初始化上传类
$f = new Upload( $savePath, $fileFormat, $maxSize, $overwrite);
//如果想生成缩略图,则调用成员函数 $f->setThumb();
//参数列表: setThumb($thumb, $thumbWidth = 0,$thumbHeight = 0)
//$thumb=1 表示要生成缩略图,不调用时,其值为 0
//$thumbWidth 缩略图宽,单位是像素(px),留空则使用默认值 130
//$thumbHeight 缩略图高,单位是像素(px),留空则使用默认值 130
$f->setThumb(1);
//参数中的uploadinput是表单中上传文件输入框input的名字
//后面的0表示不更改文件名,若为1,则由系统生成随机文件名
if (!$f->run('uploadinput',1)){
//通过$f->errmsg()只能得到最后一个出错的信息,
//详细的信息在$f->getInfo()中可以得到。
echo $f->errmsg()."<br>\n";
}
//上传结果保存在数组returnArray中。
echo "<pre>";
print_r($f->getInfo());
echo "</pre>";
}
}else{
?>
<form enctype="multipart/form-data" action="" method="POST">
Send this file: <br />
<input name="uploadinput[]" type="file"><br />
<input name="uploadinput[]" type="file"><br />
<input name="uploadinput[]" type="file"><br />
<input type="submit" value="Send File"><br />
</form>
<?php
}
//我们上传一个已经存在了的图片文件,
//一个正常的图片文件,和一个不允许上传的文件,
//输出结果如下
/*
The uploaded file is Unallowable!
Array
(
[0] => Array
(
[name] => boy.jpg
[saveName] => boy.jpg
[size] => 137
[type] => image/pjpeg
[error] => File exist already!
)
[1] => Array
(
[name] => girl.JPG
[saveName] => girl.JPG
[size] => 31
[type] => image/pjpeg
[originalHeight] => 450
[originalWidth] => 600
)
[2] => Array
(
[name] => test.wma
[saveName] => test.wma
[size] => 971
[type] => audio/x-ms-wma
[error] => The uploaded file is Unallowable!
)
)
*/
?>
<?php
class ZipAllFloder{
var $cachelist = array();
var $datasec = array();
var $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
function StartWork($dir){
$result = $this->GetList($dir);
$this->ClearCache();
return $result;
}
function ReadAndExport($filelist,$zipfilename){
if (count($filelist)>0){
foreach($filelist as $filename){
if (is_file($filename)){
$fp = fopen ($filename, "r");
$content = @fread ($fp,filesize($filename));
fclose ($fp);
$filename = basename($filename);
$this -> addFile($content, $filename);
}
}
}else{
$this -> addFile("This folder have none a single file!","nofile.log");
}
$out = $this -> outfile();
$this -> IniVars();
$fp = fopen($zipfilename,"w");
fwrite($fp,$out,strlen($out));
fclose($fp);
$this -> cachelist[] = $zipfilename;
}
function GetList($dir){
if (file_exists($dir)){
$handle = opendir($dir);
while($files = readdir($handle)){
if (($files==".")||($files=="..")) continue;
if(is_dir($dir."/".$files)){
$this -> GetList($dir."/".$files);
}else{
$filelist[] = $dir."/".$files;
}
}
closedir($handle);
$zipfilename = dirname($dir)."/[FOLDER]".basename($dir).".zip";
$this -> ReadAndExport($filelist,$zipfilename);
}
return $zipfilename;
}
function ClearCache(){
if($num = count($this ->cachelist)){
for($i=0;$i<$num-1;$i++){
@unlink($this ->cachelist[$i]);
}
}
}
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;
}
function unix2DosTime($unixtime = 0) {
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
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);
}
function addFile($data, $name, $time = 0){
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->unix2DosTime($time));
$hexdtime = '\x' . $dtime[6] . $dtime[7]
. '\x' . $dtime[4] . $dtime[5]
. '\x' . $dtime[2] . $dtime[3]
. '\x' . $dtime[0] . $dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
$fr = "\x50\x4b\x03\x04";
$fr .= "\x14\x00";
$fr .= "\x00\x00";
$fr .= "\x08\x00";
$fr .= $hexdtime;
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);
$c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
$fr .= pack('V', $crc);
$fr .= pack('V', $c_len);
$fr .= pack('V', $unc_len);
$fr .= pack('v', strlen($name));
$fr .= pack('v', 0);
$fr .= $name;
$fr .= $zdata;
$fr .= pack('V', $crc);
$fr .= pack('V', $c_len);
$fr .= pack('V', $unc_len);
$this -> datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
$cdrec = "\x50\x4b\x01\x02";
$cdrec .= "\x00\x00";
$cdrec .= "\x14\x00";
$cdrec .= "\x00\x00";
$cdrec .= "\x08\x00";
$cdrec .= $hexdtime;
$cdrec .= pack('V', $crc);
$cdrec .= pack('V', $c_len);
$cdrec .= pack('V', $unc_len);
$cdrec .= pack('v', strlen($name) );
$cdrec .= pack('v', 0 );
$cdrec .= pack('v', 0 );
$cdrec .= pack('v', 0 );
$cdrec .= pack('v', 0 );
$cdrec .= pack('V', 32 );
$cdrec .= pack('V', $this -> old_offset );
$this -> old_offset = $new_offset;
$cdrec .= $name;
$this -> ctrl_dir[] = $cdrec;
}
function outfile(){
$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";
}
}
$zip = new ZipAllFloder();
$str = $zip->StartWork("./baby");
echo $str;
?>
<style>
#image{background-image:url(test1.jpg);width:1000px;height:200px;border:1px solid #000}
/*绝对定位很重要*/
#helper{position:absolute;width:100px;height:100px;border:1px solid #a9b53f;cursor:pointer;display:none;background-color:#999;top:30px;left:30px}
</style>
<script>
//目标源
var target;
//拖拽辅助容器
var helper;
//鼠标默认状态(false=没有按下)
var iMouseDown=false;
//当前的目标源
var ctar;
//鼠标偏移量
var mouseOff;
//ajax相关
var ajax;
//继承number类的NANA0,用途为:如果一个数为100px会返回100。
Number.prototype.NaN0=function(){return isNaN(this)?0:this;}
//初始化AJAX
function createRequest(){
var ajax;
if(window.ActiveXObject){
try{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
ajax = false;
}
}else{
try{
ajax = new XMLHttpRequest();
}catch(e){
ajax = false;
}
}
if(!ajax){
alert("Error creating the XMLHttpRequest object.");
}else{
return ajax;
}
}
//反送AJAX请求
function cutp(cutC){
ajax=createRequest();
ajax.onreadystatechange = action;
//发送请求的URL
url = "path=./test1.jpg&x="+parseInt(cutC.style.left)+"&y="+parseInt(cutC.style.top)+"&width="+parseInt(cutC.offsetWidth)+"&height="+parseInt
(cutC.offsetHeight);
window.status = url;
ajax.open("GET", "image.php?"+url, true);
ajax.send(null);
}
function action(){
var show = document.getElementById("show");
//如果SHOW这个容器原先有子节点,就清楚子节点
if(show.hasChildNodes()){
show.removeChild(show.childNodes[0]);
}
//状态为4&200的时候返回信息
if(ajax.readyState==4&&ajax.status==200){
show.innerHTML = ajax.responseText;
}
}
//创建可拖拽容器
function createContainer(arg){
helper = document.getElementById('helper');
//设置属性
helper.setAttribute("cut",1);
arg.onmouseover = function(){
helper.style.display="block";
}
arg.onmouseout = function(){
helper.style.display="none";
}
helper.ondblclick = function(){
cutp(helper);
}
}
//获取鼠标位置
function mouseCoords(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
//获取鼠标在当前容器的偏移量
function getMouseOffset(target, ev){
ev = ev || window.event;
var docPos = getPosition(target);
var mousePos = mouseCoords(ev);
return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}
//获取鼠标相对父节点的偏移量
function getPosition(e){
var left = 0;
var top = 0;
while (e.offsetParent){
left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
top += e.offsetTop + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
e = e.offsetParent;
}
left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
top += e.offsetTop + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
return {x:left, y:top};
}
//鼠标移动处罚的函数
function mouseMove(ev){
ev = ev||window.event;
var tar = ev.target||ev.srcElement;
var mousePos = mouseCoords(ev);
var rootar = tar.parentNode;
var mouseOf = getPosition(rootar);
//判断状态
if(iMouseDown&&mouseOff){
var limLefX=mouseOf.x+rootar.offsetWidth-tar.offsetWidth;
var limBottomY =mouseOf.y+rootar.offsetHeight-tar.offsetHeight;
var conLeft = mousePos.x-mouseOff.x;
var conTop = mousePos.y-mouseOff.y;
if(conLeft>=mouseOf.x&&conLeft<=limLefX){
helper.style.left = mousePos.x-mouseOff.x;
}
if(conTop>=mouseOf.y&&conTop<=limBottomY){
helper.style.top = mousePos.y-mouseOff.y;
}
}
}
//鼠标按键起来的函数
function mouseUp(){
iMouseDown = false;
}
//按下鼠标按键的函数
function mouseDown(ev){
iMouseDown = true;
ev = ev||window.event;
var tar = ev.target||ev.srcElement;
if(tar.getAttribute("cut")){
var hmouseOff = getPosition(tar);
helper.style.left = hmouseOff.x;
helper.style.top = hmouseOff.y;
mouseOff = getMouseOffset(tar,ev);
}
}
//监听事件
document.onmouseup = mouseUp;
document.onmousemove = mouseMove;
document.onmousedown = mouseDown;
window.onload=function(){
target = document.getElementById("image");
createContainer(target);
}
</script>
<div id="image" class="im"><div id="helper" class="drag">#dragHelper</div></div>
<div id="show"></div>
相关文章
- 以前我们开发大型项目时都会用到svn来同步,因为开发产品的人过多,所以我们会利用软件来管理,今天发有一居然可以利用php来管理svn哦,好了看看吧。 代码如下 ...2016-11-25
- 操作类就是把一些常用的一系列的数据库或相关操作写在一个类中,这样调用时我们只要调用类文件,如果要执行相关操作就直接调用类文件中的方法函数就可以实现了,下面整理了...2016-11-25
- 我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
- 最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
- 有一种方法,可以不打开网站而直接查看到这个网站的源代码.. 这样可以有效地防止误入恶意网站... 在浏览器地址栏输入: view-source:http://...2016-09-20
- <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
- 本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
- 本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
- 本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
- 本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
- php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
- 本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25
- 公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
- 其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
- 本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
- 一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
- 微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
- 无限级分类在开发中经常使用,例如:部门结构、文章分类。无限级分类的难点在于“输出”和“查询”,例如 将文章分类输出为<ul>列表形式; 查找分类A下面所有分类包含的文章。1.实现原理 几种常见的实现方法,各有利弊。其中...2015-10-23
- Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20