PHP使用ZIP Functions处理zip压缩文件
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
<?php
if(file_exists('test.zip'))
{
$zip=zip_open(realpath('test.zip'));
if(is_resource($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);
}else{
echo"cannotopenthefile:test.zip";
}
}else{
echo"cannotfindthefile:test.zip";
}
?>
3.
<!--D(["mb","需要注意的是:\n\u003cbr\>\u003cbr\>\u003c/span\>\u003c/font\>a. 上面程序的第一句将会错误;\u003cbr\>$zip \u003d zip_open("test.zip");\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('test.zip'));\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
页:
[1]