php对zip文件解压和压缩
<?php
/**
* @author wyt
*
*/
class zip {
private $_zipObj=null;
private $_zipfcArr=array();
private $_basePath=null;
private $_zipName;
/**
* init
* @param zip文件名称 $zipName
*/
function __construct($zipName){
$this->_zipName=$zipName;
$this->_zipObj=new rezip();
}
/**
* 压缩一个文件夹
* @param 目录名称 $path
*/
public function tozip($path){
$this->_basePath=$path;
$this->_basePath.='/';
$this->direct($path);
$this->_zipObj->Add($this->_zipfcArr,1);
//写入文件
if(@fputs(@fopen($this->_zipName,"wb"),$this->_zipObj->get_file())) return $this->_zipName;
return false;
}
/**
* 解压zip文件
* @param 解压到的文件夹 $destPath
*/
public function unzip($destPath){
if(!file_exists($destPath)) @mkdir($destPath,0777,true);
return $this->_zipObj->Extract($this->_zipName,$destPath);
}
function direct($path){
$handler=opendir($path);
while(($file=readdir($handler))!==false){
if($file=='.'||$file=='..') continue;
$tmp=$path.'/'.$file;
$filename=str_replace($this->_basePath,'',$tmp);
if(is_dir($tmp)){
$this->direct($tmp);
}else{
//生成的zip 文件名
echo $tmp."\n";
$filesize=@filesize($tmp);
$fp=@fopen($tmp,rb);
$this->_zipfcArr[]=Array($filename,@fread($fp,$filesize));
@fclose($fp);
}
}
closedir($handler);
}
}
/**
* 压缩类,进行了小小的改动
*
*/
class rezip{
var $datasec, $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0; var $dirs = Array(".");
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->Re
相关文档:
Session简介
session 分成两部分,session空间存放于服务器端,打开空间的ID 存放于 客户端的cookie, 如果客户端关闭了cookie,session就不能正常的使用。
Session的中文译名叫做“会话”,其本来的含义是指有始有终的一系列动作/消息,比如打电话时从拿起电话拨号到挂断电话这中间的一系列过程可以称 ......
一直都以为在PHP中,' 和"是没有区别的,今天看了中原大学孙仲岳老师的视频教程,才发现,这两者用法是有区别的,举个简单的例子:
1.php
<?$str='冰冻鱼';
echo '$str 的博客地址是http://www.webxuexi.net' ;//注意这里是单引号哦
?>
2.php
<?
$str='冰冻鱼';
echo ......
BUGTRAQ ID: 36555
CVE ID: CVE-2009-3557
PHP是广泛使用的通用目的脚本语言,特别适合于Web开发,可嵌入到HTML中。
PHP的tempnam()中的错误可能允许绕过safe_mode限制。以下是ext/standard/file.c中的有漏洞代码段:
PHP_FUNCTION(tempnam)
{
char *dir, *prefix;
int dir_len, prefix_len;
size_t p_len;
char ......
PHP 中巧用数组降低程序的时间复杂度
王 丹丹, 高级软件工程师, IBM
2009 年 11 月 26 日
本文主要是介绍在 PHP 的编程中,如何巧用数组来降低因多层循环而引起的时间复杂度的问题。特别是当程序需要多次与数据库交互时,用此方法来优化你的代码,将会带给意想不到的效果。
通常开发人员在写程序的时候,往往是把已经设 ......