您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php中运用zip

2025/8/6 0:18:06发布19次查看
php中使用zip
  在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(); }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product