【问题标题】:This code compress a SQL file to zip using Php. I need to set password for the zip file produced此代码使用 Php 将 SQL 文件压缩为 zip。我需要为生成的 zip 文件设置密码
【发布时间】:2017-12-08 05:15:51
【问题描述】:

此代码有助于将 SQL 文件转换为 PHP 中的 zip 文件。

这里将一个 SQL 文件压缩为一个 zip 文件。

我只需要为此设置密码。

我可以使用 PHP-java 桥来实现吗?

function dumpOutput() { 
    if (!class_exists('ZipArchive')) {
        return array();
    }
    return array('zip' => 'ZIP');
}

function _zip($string, $state) {
    // ZIP can be created without temporary file by gzcompress - see PEAR File_Archive
    $this->data .= $string;
    if ($state & PHP_OUTPUT_HANDLER_END) {
        $zip = new ZipArchive;
        $zipFile = tempnam("", "zip");
        $zip->open($zipFile, ZipArchive::OVERWRITE); // php://output is not supported
        $zip->addFromString($this->filename, $this->data);
        $zip->close();
        $return = file_get_contents($zipFile);  
        unlink($zipFile);
        return $return;
    }
    return "";
}

【问题讨论】:

    标签: php php-java-bridge adminer


    【解决方案1】:

    ZipArchive 类似乎不支持密码设置。它只支持打开受密码保护的 zip 文件。

    有关详细信息,请参阅以下页面。 http://php.net/manual/zh/ziparchive.setpassword.php

    【讨论】:

    • 我知道这就是为什么我问我是否可以使用 php-java 桥来实现这一点。
    • 我在 PHP7.2 中看到了一个使用 ZipArchive::setEncryptionName 的解决方案。我没有PHP7.2的生产环境,抱歉没有验证。
    猜你喜欢
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多