Blogger Information
Blog 26
fans 1
comment 1
visits 35569
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php 压缩图片 文件 目录
Bystander
Original
1153 people have browsed it

<?php

// 压缩文件 图片

$fileList = array(

    "c:/wamp/www/log.txt",

    "c:/wamp/www/weixin.class.php"

);

$filename = "test.zip";

$zip = new ZipArchive();

$zip->open($filename,ZipArchive::CREATE);   //打开压缩包

foreach($fileList as $file){

    $zip->addFile($file,basename($file));   //向压缩包中添加文件

}

$zip->close();  //关闭压缩包


//压缩目录

function addFileToZip($path,$zip){

    $handler=opendir($path); //打开当前文件夹由$path指定。

    while(($filename=readdir($handler))!==false){

        if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作

            if(is_dir($path."/".$filename)){// 如果读取的某个对象是文件夹,则递归

addFileToZip($path."/".$filename, $zip);

            }else{ //将文件加入zip对象

                $zip->addFile($path."/".$filename);

            }

        }

    }

    @closedir($path);

}

$zip=new ZipArchive();

if($zip->open('rsa.zip', ZipArchive::OVERWRITE)=== TRUE){

    addFileToZip('rsa/', $zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法

    $zip->close(); //关闭处理的zip文件

}

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post