当前位置: 首页 > 图文教程 > 网络编程 > PHP > php在线打包/解包

PHP
在PHP中以root身份运行外部命令
PHP编程常用技巧四则
实例学习PHP之投票程序篇
PHP中的加密功能
PHP VS ASP
PHP生成动态WAP页面
PHP中for循环语句的几种变型
PHP5.0对象模型探索之对象串行化
PHP5.0对象模型探索之重载
浅议PHP程序开发中的模板选择
用PHP写的身份证验证程序
PHP.MVC的模板标签系统之初识PHP.MVC
PHP程序加速探索之代码优化
PHP程序加速探索之压缩输出gzip
用PHP文件上传的具体思路及实现
使用PHP编写基于Web的文件管理系统
理解PHP中的MVC编程之控制器
PHP程序加速探索之缓存输出
让你的PHP引擎全速运转的三个绝招
PHP程序加速探索之加速工具软件

PHP 中的 php在线打包/解包


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-19   浏览: 597 ::
收藏到网摘: n/a

  1. /** 
  2. * @ 在线打包函数 createZip($zipfile, $dir) 
  3. * @ 在线解包函数 extractZip($zipfile, $dir) 
  4. * @ $zipfile 压缩包名称 
  5. * @ $dir 打包/解包目录 
  6. * @ by 李奕权 
  7. */  
  8. function createZip($zipfile$dir){  
  9.   $zip = new ZipArchive;  
  10.   if($zip->open($zipfile, ZipArchive::CREATE)){  
  11.     $files = listdir($dir);  
  12.     foreach($files as $path) {  
  13.       if($zip->addFile($path,str_replace("./","",str_replace("\\","/",$path))) == flase) exit('Failture, stoped from '.$path);  
  14.     }  
  15.     $zip->close();  
  16.   }  
  17. }  
  18.   
  19. function extractZip($zipfile$dir){  
  20.   $zip = new ZipArchive;  
  21.   if ($zip->open($zipfile) === true) {  
  22.       $zip->extractTo($dir);  
  23.       $zip->close();  
  24.   } else {  
  25.       echo 'Failture!';  
  26.   }