PHP使用ZIP Functions处理zip压缩文件

news/2024/7/10 22:13:50 标签: PHP, ASP.net, ASP, .net, EXT
PHP访问ZIP压缩文件

1. 对于PHP5.0以上只需要首先 查看php目录的ext下有没有php_zip.dll文件,然后 打开php.ini中的extension=php_zip<wbr></wbr>.dll

2.
然后就可以使用PHP的zip function了

实例程序Zip Usage Example
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" /> <? php
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
if ( file_exists ( ' test.zip ' ))
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />{
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
$zip = zip_open( realpath ( ' test.zip ' ));
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
if ( is_resource ( $zip )){
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
while ( $zip_entry = zip_read( $zip )){
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " Name: " . zip_entry_name( $zip_entry ) . " " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " ActualFilesize: " . zip_entry_filesize( $zip_entry ) . " " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " CompressedSize: " . zip_entry_compressedsize( $zip_entry ) . " " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " CompressionMethod: " . zip_entry_compressionmethod( $zip_entry ) . " " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
if (zip_entry_open( $zip , $zip_entry , " r " )){
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " FileContents: " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
$buf = zip_entry_read( $zip_entry , zip_entry_filesize( $zip_entry ));
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " $buf " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />zip_entry_close(
$zip_entry );
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />}
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />}
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />zip_close(
$zip );
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />}
else {
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " cannotopenthefile:test.zip " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />}
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />}
else {
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
echo " cannotfindthefile:test.zip " ;
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />}
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
?>
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />
.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" />


3.
<!-- D(["mb","需要注意的是:\n\u003cbr\>\u003cbr\>\u003c/span\>\u003c/font\>a. 上面程序的第一句将会错误;\u003cbr\>$zip \u003d zip_open(&quot;test.zip&quot;);\u003cbr\>正确情况下$zip将返回一个resource变量,如果错误的话\u003cbr\>Returns a resource handle for later use with zip_read() and zip_close() or returns the number of error if filename does not exist or in case of other error.\n\u003cbr\>会返回一个预定义的整形常量;\u003cbr\>\u003cbr\>b.\u003cbr\>zip_open函数执行失败的原因是zip_open函数中zi\u003cWBR\>p文件的路径不能使用相对路径\u003cbr\>举例说明:\u003cbr\>如果在以上zip_test.php路径下有test.zip,正确的需要添加上realpath为\u003cbr\>$zip\u003dzip_open(realpath(&#39;test.zip&#39;));\u003cbr\>\u003cbr\>\u003cbr\>\u003cbr\>详情参考\u003cbr\>\u003ca href\u003d\"http://www.w3schools.com/php/php_ref_zip.asp\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\"\>\nhttp://www.w3schools.com/php\u003cWBR\>/php_ref_zip.asp\u003c/a\>\u003cbr\>\u003ca href\u003d\"http://cn.php.net/zip\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\"\>http://cn.php.net/zip\u003c/a\>\u003cbr\>\u003ca href\u003d\"http://cn.php.net/manual/zh/function.zip-open.php\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\"\>http://cn.php.net/manual/zh\u003cWBR\>/function.zip-open.php\n\u003c/a\>\u003cbr\>\u003cbr\>\n",0] ); D(["ce"]); //--> 需要注意的是:

a. 上面程序的第一句将会错误;
$zip = zip_open("test.zip");
正确情况下$zip将返回一个resource变量,如果错误的话
Returns a resource handle for later use with zip_read() and zip_close() or returns the number of error if filename does not exist or in case of other error.
会返回一个预定义的整形常量;

b.
zip_open函数执行失败的原因是zip_open函数中zi
<wbr></wbr>p文件的路径不能使用相对路径
举例说明:
如果在以上zip_test.php路径下有test.zip,正确的需要添加上realpath为
$zip=zip_open(realpath('test.zip'));



详情参考
http://www.w3schools.com/php<wbr></wbr>/php_ref_zip.asp
http://cn.php.net/zip
http://cn.php.net/manual/zh<wbr></wbr>/function.zip-open.php

http://www.niftyadmin.cn/n/601335.html

相关文章

线性判别分析LDA的思想

1、分类原理&#xff1a; 分类思想&#xff1a;训练时&#xff0c;设法将训练样本投影到一条直线上&#xff0c;这条直线上&#xff0c;同类样本的投影点尽可能接近&#xff0c;异类样本点的类别中心尽可能远离。预测时&#xff0c;将样本投影到学得的直线上&#xff0c;根据投…

ubuntu14.04 3D桌面效果制作

参考&#xff1a;http://www.360doc.com/content/14/0919/22/11681374_410808557.shtml转载于:https://www.cnblogs.com/perfy/p/5166682.html

Perl5的教程

http://net.pku.edu.cn/~yhf/perl/perl.html

Javascript(AJAX) 开发工具:Aptana安装

简单介绍两种安装方法&#xff1a;方法一&#xff1a;在线安装&#xff1a;在 Eclipse 的 Help 菜单中&#xff0c;选择 Software Updates->Find and Install...&#xff0c;这会打开 Install/Update 弹出窗口。 在 Install/Update 弹出窗口中&#xff0c;选择 Search for …

提高深度学习(和机器学习)性能的思路

文章目录1. 通过数据提升性能2、通过算法提升性能3. 通过算法调参提升性能4、通过嵌套模型提升性能总结提升思路分为以下4部分&#xff0c;通常来讲&#xff0c;随着列表自上而下&#xff0c;性能的提升也将变小。部分思路只适用于人工神经网络&#xff0c;但是大部分是通用的。…

8位并行左移串行转换电路_「学术论文」基于TMS320C6748的多路串行通信接口设计与实现...

摘要&#xff1a;在嵌入式飞行控制系统中&#xff0c;为了满足小型化和集成化的要求&#xff0c;需要控制多个串口与外部设备通信。采用TMS320C6748作为核心处理器&#xff0c;通过EMIF总线实现和异步通信协议芯片TL16C754并行通信&#xff0c;采用3-8译码器74LS138扩展多位片选…

今天,影响了一位试用期员工的去留

朱金灿今天&#xff0c;我的心情有点惆怅。之前公司的一个试用期员工&#xff0c;原来在平台开发部门&#xff0c;后来跟着我做项目。试用期将满&#xff0c;人事部门的人问我他的表现如何&#xff0c;我说&#xff1a;“一般&#xff0c;没有令人信服的表现”。可能因为我的评…

美媒:强强联手 优酷马铃薯华为抢占互联网电视商场

据美国Motley Fool站点4月22日报道&#xff0c;华为携手优酷马铃薯联合打造了一款名为“悦盒”的智能机顶盒&#xff0c;并已于本月21日在京东敞开预售。这些年。国内网络电视机顶盒商场迅速发展&#xff0c;悦盒好像有些缓不济急。但是两大业界巨子强强联手&#xff0c;仍是让…