电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

PHP擴展之壓縮與歸檔擴展3——Zip

瀏覽:107日期:2022-09-15 15:14:44

此擴展可以讓你透明地讀寫ZIP壓縮文檔以及它們里面的文件。

在PHP5.2以后,為了使用這些函數,必須在編譯 PHP 時用?--enable-zip?配置選項來提供 zip 支持。

Example #1 創建一個 Zip 歸檔

<?php $zip = new ZipArchive(); $filename = './test112.zip'; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {exit('cannot open <$filename>n'); } $zip->addFromString('testfilephp.txt' . time(), '#1 This is a test string added as testfilephp.txt.n'); $zip->addFromString('testfilephp2.txt' . time(), '#2 This is a test string added as testfilephp2.txt.n'); $zip->addFile($thisdir . '/too.php','/testfromfile.php'); echo 'numfiles: ' . $zip->numFiles . 'n'; echo 'status:' . $zip->status . 'n'; $zip->close();?>

Example #2 輸出文檔細節和列表

<?php $za = new ZipArchive(); $za->open(’test_with_comment.zip’); print_r($za); var_dump($za); echo 'numFiles: ' . $za->numFiles . 'n'; echo 'status: ' . $za->status . 'n'; echo 'statusSys: ' . $za->statusSys . 'n'; echo 'filename: ' . $za->filename . 'n'; echo 'comment: ' . $za->comment . 'n'; for ($i=0; $i<$za->numFiles;$i++) {echo 'index: $in';print_r($za->statIndex($i)); } echo 'numFile:' . $za->numFiles . 'n';?>

Example #3 Zip 流封裝,讀取一個 OpenOffice 文件的元信息

<?php $reader = new XMLReader(); $reader->open(’zip://’ . dirname(__FILE__) . ’/test.odt#meta.xml’); $odt_meta = array(); while ($reader->read()) {if ($reader->nodeType == XMLREADER::ELEMENT) { $elm = $reader->name;} else { if ($reader->nodeType == XMLREADER::END_ELEMENT && $reader->name == ’office:meta’) {break; } if (!trim($reader->value)) {continue; } $odt_meta[$elm] = $reader->value;} } print_r($odt_meta);?>

此例使用了舊的 API(PHP 4),它打開了一個 ZIP 文件歸檔,讀取歸檔里的每個文件,并輸出文件內容。此例用到的?test2.zip?文檔是 ZZIPlib 源分布里測試文檔中的一個。

Example #4 Zip 使用范例

<?php $zip = zip_open('/tmp/test2.zip'); if ($zip) {while ($zip_entry = zip_read($zip)) { echo 'Name: ' . zip_entry_name($zip_entry) . 'n'; echo 'Actual Filesize: ' . zip_entry_filesize($zip_entry) . 'n'; echo 'Compressed Size: ' . zip_entry_compressedsize($zip_entry) . 'n'; echo 'Compression Method: ' . zip_entry_compressionmethod($zip_entry) . 'n'; if (zip_entry_open($zip, $zip_entry, 'r')) { echo 'File Contents:n'; $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); echo '$bufn'; zip_entry_close($zip_entry); } echo 'n';}zip_close($zip); }?>

?ZipArchive 類

ZipArchive::addEmptyDir?— Add a new directoryZipArchive::addFile?— Adds a file to a ZIP archive from the given pathZipArchive::addFromString?— Add a file to a ZIP archive using its contentsZipArchive::addGlob?— Add files from a directory by glob patternZipArchive::addPattern?— Add files from a directory by PCRE patternZipArchive::close?— Close the active archive (opened or newly created)ZipArchive::deleteIndex?— delete an entry in the archive using its indexZipArchive::deleteName?— delete an entry in the archive using its nameZipArchive::extractTo?— Extract the archive contentsZipArchive::getArchiveComment?— Returns the Zip archive commentZipArchive::getCommentIndex?— Returns the comment of an entry using the entry indexZipArchive::getCommentName?— Returns the comment of an entry using the entry nameZipArchive::getFromIndex?— Returns the entry contents using its indexZipArchive::getFromName?— Returns the entry contents using its nameZipArchive::getNameIndex?— Returns the name of an entry using its indexZipArchive::getStatusString?— Returns the status error message, system and/or zip messagesZipArchive::getStream?— Get a file handler to the entry defined by its name (read only).ZipArchive::locateName?— Returns the index of the entry in the archiveZipArchive::open?— Open a ZIP file archiveZipArchive::renameIndex?— Renames an entry defined by its indexZipArchive::renameName?— Renames an entry defined by its nameZipArchive::setArchiveComment?— Set the comment of a ZIP archiveZipArchive::setCommentIndex?— Set the comment of an entry defined by its indexZipArchive::setCommentName?— Set the comment of an entry defined by its nameZipArchive::statIndex?— Get the details of an entry defined by its index.ZipArchive::statName?— Get the details of an entry defined by its name.ZipArchive::unchangeAll?— Undo all changes done in the archiveZipArchive::unchangeArchive?— Revert all global changes done in the archive.ZipArchive::unchangeIndex?— Revert all changes done to an entry at the given indexZipArchive::unchangeName?— Revert all changes done to an entry with the given name.

相關函數

zip_close?— Close a ZIP file archivezip_entry_close?— Close a directory entryzip_entry_compressedsize?— Retrieve the compressed size of a directory entryzip_entry_compressionmethod?— Retrieve the compression method of a directory entryzip_entry_filesize?— Retrieve the actual file size of a directory entryzip_entry_name?— Retrieve the name of a directory entryzip_entry_open?— Open a directory entry for readingzip_entry_read?— Read from an open directory entryzip_open?— Open a ZIP file archivezip_read?— Read next entry in a ZIP file archive
標簽: PHP
相關文章:
主站蜘蛛池模板: 臭氧老化试验箱,高低温试验箱,恒温恒湿试验箱,防水试验设备-苏州亚诺天下仪器有限公司 | 脑钠肽-白介素4|白介素8试剂盒-研域(上海)化学试剂有限公司 | 单电机制砂机,BHS制砂机,制沙机设备,制砂机价格-正升制砂机厂家 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 锻造液压机,粉末冶金,拉伸,坩埚成型液压机定制生产厂家-山东威力重工官方网站 | 精密钢管,冷拔精密无缝钢管,精密钢管厂,精密钢管制造厂家,精密钢管生产厂家,山东精密钢管厂家 | 胀套-锁紧盘-风电锁紧盘-蛇形联轴器「厂家」-瑞安市宝德隆机械配件有限公司 | 减速机电机一体机_带电机减速器一套_德国BOSERL电动机与减速箱生产厂家 | 亮点云建站-网站建设制作平台| 气体热式流量计-定量控制流量计(空气流量计厂家)-湖北南控仪表科技有限公司 | 吸污车_吸粪车_抽粪车_电动三轮吸粪车_真空吸污车_高压清洗吸污车-远大汽车制造有限公司 | 谈股票-今日股票行情走势分析-牛股推荐排行榜 | 螺钉式热电偶_便携式温度传感器_压簧式热电偶|无锡联泰仪表有限公司|首页 | 马尔表面粗糙度仪-MAHR-T500Hommel-Mitutoyo粗糙度仪-笃挚仪器 | 液氮罐_液氮容器_自增压液氮罐-北京君方科仪科技发展有限公司 | 首页|光催化反应器_平行反应仪_光化学反应仪-北京普林塞斯科技有限公司 | 粒米特测控技术(上海)有限公司-测功机_减速机测试台_电机测试台 | 美的商用净水器_美的直饮机_一级代理经销商_Midea租赁价格-厂家反渗透滤芯-直饮水批发品牌售后 | 浙江寺庙设计-杭州寺院设计-宁波寺庙规划_汉匠 | 广州监控安装公司_远程监控_安防弱电工程_无线wifi覆盖_泉威安防科技 | IHDW_TOSOKU_NEMICON_EHDW系列电子手轮,HC1系列电子手轮-上海莆林电子设备有限公司 | 深圳市宏康仪器科技有限公司-模拟高空低压试验箱-高温防爆试验箱-温控短路试验箱【官网】 | 破碎机_上海破碎机_破碎机设备_破碎机厂家-上海山卓重工机械有限公司 | 软文发布平台 - 云软媒网络软文直编发布营销推广平台 | 粤丰硕水性环氧地坪漆-防静电自流平厂家-环保地坪涂料代理 | 宝宝药浴-产后药浴-药浴加盟-艾裕-专注母婴调养泡浴 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 阻垢剂,反渗透阻垢剂,缓蚀阻垢剂-山东普尼奥水处理科技有限公司 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 成都珞石机械 - 模温机、油温机、油加热器生产厂家 | 企典软件一站式企业管理平台,可私有、本地化部署!在线CRM客户关系管理系统|移动办公OA管理系统|HR人事管理系统|人力 | 周易算网-八字测算网 - 周易算网-宝宝起名取名测名字周易八字测算网 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | 中式装修设计_全屋定制家具_实木仿古门窗花格厂家-喜迎门 | 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 双舌接地线-PC68数字式高阻计-ZC36|苏海百科 | 红外光谱仪维修_二手红外光谱仪_红外压片机_红外附件-天津博精仪器 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 大鼠骨髓内皮祖细胞-小鼠神经元-无锡欣润生物科技有限公司 | 双吸泵,双吸泵厂家,OS双吸泵-山东博二泵业有限公司 | 氧化锆陶瓷_氧化锆陶瓷加工_氧化锆陶瓷生产厂家-康柏工业陶瓷有限公司 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 |