当前位置:首页 » 编程语言 » php读取zip

php读取zip

发布时间: 2025-01-31 23:35:33

1. 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>

2. php 读取zip包的大小

functionget_zip_originalsize($filename){
$size=0;
$resource=zip_open($filename);
while($dir_resource=zip_read($resource)){
$size+=zip_entry_filesize($dir_resource);}
zip_close($resource);return$size;}
$size=get_zip_originalsize('file.zip');
echo"originalsize:$sizebytes ";

3. PHP怎么解压ZIP文件

?php

$zip=zip_open("/tmp/test2.zip");

if($zip){

while($zip_entry=zip_read($zip)){
echo"Name:".zip_entry_name($zip_entry)." ";
echo"ActualFilesize:".zip_entry_filesize($zip_entry)." ";
echo"CompressedSize:".zip_entry_compressedsize($zip_entry)." ";
echo"CompressionMethod:".zip_entry_compressionmethod($zip_entry)." ";

if(zip_entry_open($zip,$zip_entry,"r")){
echo"FileContents: ";
$buf=zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));
echo"$buf ";

zip_entry_close($zip_entry);
}
echo" ";

}

zip_close($zip);

}

?>

4. 请高手指点:PHP 如何解压缩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>';
}
}
}

5. php怎样实现对zip文件的加密和解密

使用PHPZip类就可以解决的。以下是网上找到的例子。

$zipfiles=array("/root/pooy/test1.txt","/root/pooy/test2.txt");
$z=newPHPZip();
//$randomstr=random(8);
$zipfile=TEMP."/photocome_".$groupid.".zip";
$z->Zip($zipfiles,$zipfile);
<?php
#
#PHPZipv1.2bySext([email protected])2002-11-18
#(Changed:2003-03-01)
#
#Makesziparchive
#
#Basedon"Zipfilecreationclass",useszLib
#
#
classPHPZip
{
functionZip($dir,$zipfilename)
{
if(@function_exists('gzcompress'))
{
$curdir=getcwd();
if(is_array($dir))
{
$filelist=$dir;
}
else
{
$filelist=$this->GetFileList($dir);
}
if((!empty($dir))&&(!is_array($dir))&&(file_exists($dir)))chdir($dir);
elsechdir($curdir);
if(count($filelist)>0)
{
foreach($filelistas$filename)
{
if(is_file($filename))
{
$fd=fopen($filename,"r");
$content=fread($fd,filesize($filename));
fclose($fd);
if(is_array($dir))$filename=basename($filename);
$this->addFile($content,$filename);
}
}
$out=$this->file();
chdir($curdir);
$fp=fopen($zipfilename,"w");
fwrite($fp,$out,strlen($out));
fclose($fp);
}
return1;
}
elsereturn0;
}
functionGetFileList($dir)
{
if(file_exists($dir))
{
$args=func_get_args();
$pref=$args[1];
$dh=opendir($dir);
while($files=readdir($dh))
{
if(($files!=".")&&($files!=".."))
{
if(is_dir($dir.$files))
{
$curdir=getcwd();
chdir($dir.$files);
$file=array_merge($file,$this->GetFileList("","$pref$files/"));
chdir($curdir);
}
else$file[]=$pref.$files;
}
}
closedir($dh);
}
return$file;
}
var$datasec=array();
var$ctrl_dir=array();
var$eof_ctrl_dir="x50x4bx05x06x00x00x00x00";
var$old_offset=0;
/**
*(date
*inhightwobytes,).
*
*@
*
*@
*
*@accessprivate
*/
functionunix2DosTime($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;
}//endif
return(($timearray['year']-1980)<<25)|($timearray['mon']<<21)|($timearray['mday']<<16)|
($timearray['hours']<<11)|($timearray['minutes']<<5)|($timearray['seconds']>>1);
}//endofthe'unix2DosTime()'method
/**
*Adds"file"toarchive
*
*@paramstringfilecontents
*@(maycontainsthepath)
*@
*
*@accesspublic
*/
functionaddFile($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="x50x4bx03x04";
$fr.="x14x00";//verneededtoextract
$fr.="x00x00";//genpurposebitflag
$fr.="x08x00";//compressionmethod
$fr.=$hexdtime;//lastmodtimeanddate
//"localfileheader"segment
$unc_len=strlen($data);
$crc=crc32($data);
$zdata=gzcompress($data);
$c_len=strlen($zdata);
$zdata=substr(substr($zdata,0,strlen($zdata)-4),2);//fixcrcbug
$fr.=pack('V',$crc);//crc32
$fr.=pack('V',$c_len);//compressedfilesize
$fr.=pack('V',$unc_len);//uncompressedfilesize
$fr.=pack('v',strlen($name));//lengthoffilename
$fr.=pack('v',0);//extrafieldlength
$fr.=$name;
//"filedata"segment
$fr.=$zdata;
//"datadescriptor"segment(
//servedasfile)
$fr.=pack('V',$crc);//crc32
$fr.=pack('V',$c_len);//compressedfilesize
$fr.=pack('V',$unc_len);//uncompressedfilesize
//addthisentrytoarray
$this->datasec[]=$fr;
$new_offset=strlen(implode('',$this->datasec));
//
$cdrec="x50x4bx01x02";
$cdrec.="x00x00";//versionmadeby
$cdrec.="x14x00";//versionneededtoextract
$cdrec.="x00x00";//genpurposebitflag
$cdrec.="x08x00";//compressionmethod
$cdrec.=$hexdtime;//lastmodtime&date
$cdrec.=pack('V',$crc);//crc32
$cdrec.=pack('V',$c_len);//compressedfilesize
$cdrec.=pack('V',$unc_len);//uncompressedfilesize
$cdrec.=pack('v',strlen($name));//lengthoffilename
$cdrec.=pack('v',0);//extrafieldlength
$cdrec.=pack('v',0);//filecommentlength
$cdrec.=pack('v',0);//disknumberstart
$cdrec.=pack('v',0);//internalfileattributes
$cdrec.=pack('V',32);//externalfileattributes-'archive'bitset
$cdrec.=pack('V',$this->old_offset);//relativeoffsetoflocalheader
$this->old_offset=$new_offset;
$cdrec.=$name;
//optionalextrafield,filecommentgoeshere
//savetocentraldirectory
$this->ctrl_dir[]=$cdrec;
}//endofthe'addFile()'method
/**
*Dumpsoutfile
*
*@returnstringthezippedfile
*
*@accesspublic
*/
functionfile()
{
$data=implode('',$this->datasec);
$ctrldir=implode('',$this->ctrl_dir);
return
$data.
$ctrldir.
$this->eof_ctrl_dir.
pack('v',sizeof($this->ctrl_dir)).//total#ofentries"onthisdisk"
pack('v',sizeof($this->ctrl_dir)).//total#ofentriesoverall
pack('V',strlen($ctrldir)).//sizeofcentraldir
pack('V',strlen($data)).//offsettostartofcentraldir
"x00x00";//.zipfilecommentlength
}//endofthe'file()'method
}//endofthe'PHPZip'class
?>
热点内容
sqlifthen男女 发布:2025-02-01 01:44:59 浏览:690
幻灵和安卓哪个互通 发布:2025-02-01 01:43:33 浏览:648
电脑配置够但为什么打lol掉帧 发布:2025-02-01 01:37:08 浏览:316
21款朗逸哪个配置比较划算 发布:2025-02-01 01:35:32 浏览:976
建筑动画片脚本 发布:2025-02-01 01:35:21 浏览:469
管家婆如何用阿里云服务器 发布:2025-02-01 01:29:09 浏览:649
解压耳放 发布:2025-02-01 01:20:18 浏览:175
cars算法 发布:2025-02-01 01:02:26 浏览:177
数据库超载 发布:2025-02-01 00:57:15 浏览:33
fgo安卓如何玩日服 发布:2025-02-01 00:49:40 浏览:715