您的位置:首页 > 编程语言 > PHP开发

PHP扩展之压缩与归档扩展3——Zip

2014-11-07 00:00 891 查看
此扩展可以让你透明地读写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();
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PHP扩展