Search code examples
phpphp-java-bridgeadminer

This code compress a SQL file to zip using Php. I need to set password for the zip file produced


This code helps to make SQL file to a zip file in Php.

Here a SQL file is compressed to a zip file.

All I need is to set password for this.

Can I use PHP-java bridge to make this happen?

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 "";
}

Solution

  • It seems that the ZipArchive Class doesn't support password setting. It only supports to open a password protected zip file.

    See the following page for more details. http://php.net/manual/zh/ziparchive.setpassword.php