日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

PHP自帶ZIP壓縮、解壓縮類ZipArchiv使用指南_PHP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:php開啟多進程的方法
本文實例講述了php開啟多進程的方法。分享給大家供大家參考。具體實現(xiàn)方法如下: 代碼如下: ?php $IP='192.168.1.1';//Windows電腦的IP $Port='5900'; //VNC使用的Port $ServerPort='9999';//Linux Server對外使用的Port $RemoteSocket=false;//連線到VNC的Socket func

 這篇文章主要介紹了PHP自帶ZIP壓縮、解壓縮類ZipArchiv使用指南,十分詳細,需要的朋友可以參考下

   

要使用該PHP擴展類,需要(PHP 5 >= 5.2.0, PECL zip >= 1.1.0),部分方法需要 PHP 5.2.+,且php.ini配置支持zip
對于win系統(tǒng),直接去掉php_zip.dll 擴展的注釋,然后重啟http服務(IIS或Apache)即可
Linux還沒有試驗,理論上差別不會很大

功能:
1、解壓縮zip文件
2、將文件壓縮成zip文件
3、追加文件到zip文件
4、將文件夾打包成zip文件(需要循環(huán)添加文件與創(chuàng)建空文件夾)
5、刪除壓縮文件中的條目

--------------------- ZipArchive對象常用方法介紹 ---------------------

測試約定:
測試文件為text.zip,該壓縮文件包含了三個被壓縮的文件(hello.txt、word.txt、ooxx.jpg),如下所示

 

代碼如下:
text.zip
hello.txt
word.txt
ooxx.jpg

 

打開zip文件,以便進一步操作
ZipArchive::open
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
mixed ZipArchive::open ( string $filename [, int $flags ] )

第2個參數(shù)講解

ZIPARCHIVE::OVERWRITE 總是創(chuàng)建一個新的文件,如果指定的zip文件存在,則會覆蓋掉
ZIPARCHIVE::CREATE 如果指定的zip文件不存在,則新建一個
ZIPARCHIVE::EXCL 如果指定的zip文件存在,則會報錯
ZIPARCHIVE::CHECKCONS

返回值:

如果返回值等于下面的屬性,表示對應的錯誤 或者 返回TRUE
$res == ZipArchive::ER_EXISTS File already exists.(文件已經(jīng)存在)
$res == ZipArchive::ER_INCONS Zip archive inconsistent.(壓縮文件不一致)
$res == ZipArchive::ER_INVAL Invalid argument.(無效的參數(shù))
$res == ZipArchive::ER_MEMORY Malloc failure.(內存錯誤?這個不確定)
$res == ZipArchive::ER_NOENT No such file.(沒有這樣的文件)
$res == ZipArchive::ER_NOZIP Not a zip archive.(沒有一個壓縮文件)
$res == ZipArchive::ER_OPEN Can't open file.(不能打開文件)
$res == ZipArchive::ER_READ Read error.(讀取錯誤)
$res == ZipArchive::ER_SEEK Seek error.(查找錯誤)

 

代碼如下:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
echo 'ok';
//解壓縮到test文件夾
$zip->extractTo('test');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>

 

根據(jù)壓縮文件內的列表索引,返回被壓縮文件的名稱

ZipArchive::getNameIndex
string ZipArchive::getNameIndex ( int $index [, int $flags ] )

 

代碼如下:
<?php
$zip = new ZipArchive();
$res = $zip->open('test.zip');
if ($res === TRUE) {
var_dump($zip->getNameIndex(0)); // hello.txt
var_dump($zip->getNameIndex(1)); // word.txt
var_dump($zip->getNameIndex(2)); // ooxx.jpg
} else {
echo 'failed, code:' . $res;
}
$zip->close();
?>

 

根據(jù)壓縮內的文件名稱,獲取該文件的文本流

ZipArchive::getStream
resource ZipArchive::getStream ( string $name )

 

代碼如下:
<?php
$zip = new ZipArchive();
$res = $zip->open('test.zip');
if ($res === TRUE) {
$stream = $zip->getStream('hello.txt');
} else {
echo 'failed, code:' . $res;
}
$zip->close();
$str = stream_get_contents($stream); //這里注意獲取到的文本編碼
var_dump($str);
?>

 

根據(jù)壓縮文件內的索引(從0開始)修改壓縮文件內的文件名

ZipArchive::renameIndex
bool ZipArchive::renameIndex ( int $index , string $newname )
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)

成功時返回 TRUE, 或者在失敗時返回 FALSE。

 

代碼如下:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
//把壓縮文件內第一個文件修改成newname.txt
$zip->renameIndex(0,'newname.txt');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>

 

根據(jù)壓縮文件內的文件名,修改壓縮文件內的文件名

ZipArchive::renameName
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)

 

代碼如下:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
//把壓縮文件內的word.txt修改成newword.txt
$zip->renameName('word.txt','newword.txt');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>

 

獲取壓縮文件的注釋(zip的文件注釋)

ZipArchive::getArchiveComment
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
string ZipArchive::getArchiveComment ([ int $flags ] )
參數(shù):ZipArchive::FL_UNCHANGED
如果參數(shù)設置為 ZipArchive::FL_UNCHANGED, 返回原始的還沒有改變的注釋
例如,在處理該壓縮文件時,使用setArchiveComment()方法改變或設置注釋時
如果加上ZipArchive::FL_UNCHANGED這個參數(shù),則表示獲取改變之前的注釋內容,否則獲取已經(jīng)改變的注釋內容
類似的還有:
ZipArchive::getCommentIndex 根據(jù)壓縮文件內的文件索引獲取【文件注釋】
ZipArchive::getCommentName 根據(jù)壓縮文件內的文件名稱獲取【文件注釋】
注意:這里的是文件注釋,不是壓縮文件(zip)的注釋

設置或修改壓縮文件的注釋(zip的文件注釋)
ZipArchive::setArchiveComment
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
bool ZipArchive::setArchiveComment ( string $comment )

分享:php實現(xiàn)四舍五入的方法小結
這篇文章主要介紹了php實現(xiàn)四舍五入的方法,實例總結了php實現(xiàn)四舍五入的三種常用方法,具有一定參考借鑒價值,需要的朋友可以參考下 本文實例總結了php實現(xiàn)四舍五入的方法。分享給大家供大家參考。具體分析如下: php實現(xiàn)四舍五入的三種方法,分別通過number_format函數(shù)

共2頁上一頁12下一頁
來源:模板無憂//所屬分類:PHP教程/更新時間:2015-03-04
相關PHP教程