php压缩代码
A. php如何压缩一个文件夹里面所有的文件到zip文件里面
//函数:文件压缩 //压缩参数:需要压缩的文件或文件夹(文件可为数组),压缩后的zip文件名及存放路径,压缩类型1:文件夹2:文件,后续操作1:压缩后下载;2:存放在服务器上(默认为/@Upload下) //压缩文件夹示例:Tozip("./","../".date("d-H-i-s").".zip",1,2); //压缩文件示例: // $aaa=array("../1.txt","../2.txt"); // Tozip($aaa,"../2.zip",2);FunctionTozip($Path, $ZipFile, $Typ=1, $Todo=1){//IF(!is_writeable($Path)){Exit("文件夹不可写!");}$Path=Str_iReplace("\\","/",($Path));IF(Is_Null($Path) OrEmpty($Path) Or!IsSet($Path)){ReturnFalse;}IF(Is_Null($ZipFile) OrEmpty($ZipFile) Or!IsSet($ZipFile)){ReturnFalse;} Include_once("inc/Class_Zip.php");$zip=NewPHPZip;IF(SubStr($Path,-1,1)=="/"){$Path=SubStr($Path,0, StrLen($Path)-1);} OB_end_clean();Switch($Typ){Case"1":$zip-ZipDir($Path, $ZipFile, $Todo);Break;Case"2":$zip-ZipFile($Path,
不用写,rar算法是有专利权的
RAR压缩算法是RARLab的专利,其它软件要使用或自己实现RAR算法的实作,都是要向RARLab申请许可或交钱的
zip算法php有自带的函数
====>
需求
PHP 4
The bundled PHP 4 version requires » ZZIPlib, by Guido Draheim, version 0.10.6 or later
PHP 5.2.0 or later
This extension uses the functions of » zlib by Jean-loup Gailly and Mark Adler.
=====>
所以用RAR只有通过命令行调用已经安装的rar程序实现打包,效果是一样的.具体调用方法参考各自软件说明.winrar也能用命令行调用,请看http://ke..com/view/2345.htm
C. php header 下载zip文件的问题
<?php
include("class.php");
date_default_timezone_set("PRC");//设置时区为中国
$filetype_array = array("as"=>"Flash ActionScript File","bmp"=>"BMP图像"
,"doc"=>"Microsoft Word文档","rar"=>"WinRAR 压缩文档",
"ppt"=>"Microsoft PowerPoint 演示文稿","txt"=>"文本文档",
"xls"=>"Microsoft Excel 工作表","gif"=>"GIF图像",
"jpg"=>"JPEG图像","jpeg"=>"JPEG图像","png"=>"PNG图像",
"html"=>"HTML Document","htm"=>"HTML Document",
"mp3"=>"MP3 格式声音","chm"=>"已编译的HTML帮助文件",
"fla"=>"Flash Document","mdb"=>"Microsoft Access 应用程序",
"pdf"=>"PDF 文件","swf"=>"Flash Movie","xml"=>"XML 文档",
"zip"=>"WinRAR ZIP 压缩文件","asf"=>"Windows 音频/视频文件",
"wmv"=>"Windows Media 音频/视频文件","avi"=>"视频剪辑",
"mpeg"=>"电影剪辑","exe"=>"应用程序","gz"=>"WinRAR 压缩文件",
"tar"=>"WinRAR 压缩文件","tiff"=>"TIFF 文件");
//以上为判断函数
$="./images";
$nba=opendir($);
$i=1;
echo "<table border=1px color:red>";
echo "<tr><td>I D</td><td>文件名称</td><td>大小</td><td>最后修改时间</td><td>类型</td><td>下载</td></tr>";
while ($wnba=readdir($nba))
{
if($wnba != "." && $wnba != "..")
{
$path=$."/".$wnba;
$dir=new dir($path);
$str[]=
"<tr>".
"<td>".$i++."</td>".
"<td>".$wnba."</td>".
"<td>".$dir->getsize()."</td>".
"<td>".$dir->gettime()."</td>".
"<td>".$dir->gettype()."</td>".
"<td><a href='$path'><img src=".$dir->getIcon()."></a></td>".
"</tr>\n";
}
$lines=15;//每页15行
if( " "==$cur_page) $cur_page=1;//当前页
$page=ceil(count($str)/$lines);//页数
echo $page;
for($i=($cur_page-1)*$lines ; $i <$cur_page*$lines ; $i++){//分段读出数组
echo "$str[$i] ";
}
}
echo "</table>";
closedir($nba);
?>
<table width=100%> <tr> <td align=center>
<?
for ($i=1;$i <=$page;$i++){
$i==$cur_page ? $a= " <b> ".$i. " </b> " : $a= " <a href= ".wjclass1.php. "?cur_page=$i> ".$i. " </a> ";
echo "$a ";
}
?>
</td> </tr> </table>
</td>
</tr>
</table>
D. php 怎把上传的rar zip文件 自动解压 用的是哪个函数 求高手指点 告急 谢谢 求源代码
/**
* PHP在线压缩/解压实例
*/
date_default_timezone_set('prc');
$zip = new engine_compress_decompress();
if (isset($_POST))
{
$sourcePath = ''; //默认位置
if (isset($_FILES['upfile'])) //上传文件
{
$stmp = $zip->fileUpload('upfile');
$sourcePath = $stmp['sourcefile'];
$upfileError = $stmp['error'];
}
elseif (isset($_POST['inputfile'])) //输入目录或者文件
{
$sourcePath = $_POST['inputfile'];
}
elseif (isset($_POST['decompresssourcefiles'])) //解压缩提交
{
$isDecompress = $zip->decompress($_POST['decompresssourcefiles'], $_POST['topath']);
if (!empty($isDecompress['filelist']))
{
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#decompress\'</script>';
}
}
$fileList = $zip->fileArray($sourcePath); //解压缩文件列表
if (isset($_POST['compressinputfileorfolder'])) //压缩文件目录或者文件输入
{
$sourcePath = $_POST['compressinputfileorfolder'];
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#compress\'</script>';
$compressFilelist = $zip->compressFileArray($sourcePath); //压缩文件列表
}
elseif ((isset($_POST['selectcompressfilelist'])) && (isset($_POST['compresssavefilename'])))
{
$compressFiles = $zip->compress($_POST['selectcompressfilelist'], $_POST['compresssavefilename']); //真实检测
$isCompress = $zip->CompileZipFile($compressFiles, $zip->savePath, 'all');
if (!empty($isCompress))
{
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#compress\'</script>';
}
}
}
E. php 压缩文件夹
php将文件夹打包成zip文件,参考代码如下:
functionaddFileToZip($path,$zip){
$handler=opendir($path);//打开当前文件夹由$path指定。
while(($filename=readdir($handler))!==false){
if($filename!="."&&$filename!=".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
if(is_dir($path."/".$filename)){//如果读取的某个对象是文件夹,则递归
addFileToZip($path."/".$filename,$zip);
}else{//将文件加入zip对象
$zip->addFile($path."/".$filename);
}
}
}
@closedir($path);
}
$zip=newZipArchive();
if($zip->open('images.zip',ZipArchive::OVERWRITE)===TRUE){
addFileToZip('images/',$zip);//调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
$zip->close();//关闭处理的zip文件
}