>  기사  >  백엔드 개발  >  php中使用zip

php中使用zip

WBOY
WBOY원래의
2016-06-23 14:32:47952검색

简介:这是php中使用zip的详细页面,介绍了和php,php, zip php中使用zip有关的知识、技巧、经验,和一些php源码等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=350525' scrolling='no'>   在PHP中,可以使用PHP自己的ZIP功能去为某些文件打包和解压,这点来说比其他语言
都很方便,方法小结如下:

1 打开PHP.INI中的扩展extension,启用(PHP 5.2以后有这个功能)
  extension= php_zip.dll

2 压缩文件
  
// Creating object of the ZipArchive $zip = new ZipArchive();  $ow = 1; $file= "c:\\master.zip"; if($zip->open($file,$ow?ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE) {   //增加一个文件   $zip->addFile("c:\\master.txt");      //a1.txt会被保存加压到a2.txt   $zip->addFile("c:\\a1.txt", "c:\\a2.txt");      $zip->addFile("c:\\a3.txt");      //关闭    $zip->close();     } ?>


3 解压
 
 $zip = new ZipArchive(); //打开master.zip  if ($zip->open("master.zip") === TRUE)  {   //解压的路径   $zip->extractTo("/path/to/folder/");   $zip->close(); } // 只解压一个文件  // Open master.zip for extracting single files if ($zip->open("master.zip") === TRUE)  {   // Will extract only fonts.css from master.zip to given path.   $zip->extractTo("/path/to/folder/","fonts.css");   $zip->close(); } //解压多个文件  if ($zip->open("master.zip") === TRUE)  {      $files = array("fonts.css","master.css");   $zip->extractTo("/path/to/folder/",$files);   $zip->close(); }

 

爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

http://biancheng.dnbcw.info/php/350525.html pageNo:3
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:PHP位操作符다음 기사:PHP发送邮件