0

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 "";
}
Lauraducky
  • 674
  • 11
  • 25
naresh
  • 41
  • 2
  • 9

1 Answers1

0

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

Phil
  • 1,444
  • 2
  • 10
  • 21
  • i know that that is why i asked whether i can use php-java bridge to make this happen. – naresh Dec 08 '17 at 05:33
  • I saw a solution in PHP7.2 using ZipArchive::setEncryptionName. I don't have the production environment of PHP7.2, sorry for not validating that. – Phil Dec 08 '17 at 05:45