Original Repos:
- PHP Compression Lib: https://github.com/a19836/phpcompressionlib/
- Bloxtor: https://github.com/a19836/bloxtor/
PHP Compression Lib is a PHP library to compress files or raw content using multiple compression formats, including bzip2, gzip, gzipstream, and ZIP.
In addition, it provides utilities to read, modify, and manage '.zip' archives programmatically.
To see a working example, open index.php on your server.
include "lib/compression/FileCompressionFactory.php";
$status = false;
$file_path = "/tmp/test.zip";
$class_prefix = FileCompressionFactory::getClassPrefixByType("zip"); //available values: bzip2, gzip, gzipstream, zip, none
//$class_prefix = FileCompressionFactory::getClassPrefixByExtension( pathinfo($file_path, PATHINFO_EXTENSION) ); //available values: bz2, gzip, zip
if (FileCompressionFactory::isValid($class_prefix)) {
$FileCompressionHandler = FileCompressionFactory::create($class_prefix);
$FileCompressionHandler->open($file_path);
//add your content here
$status = $FileCompressionHandler->write("some sentence here or");
$status = $status && $FileCompressionHandler->write("some other content here");
$FileCompressionHandler->close();
}
echo $status ? "Compressed!" : "Error!";include "lib/compression/FileCompressionFactory.php";
$FileCompressionHandler = FileCompressionFactory::create("Gzip");
$FileCompressionHandler->open("/tmp/test.sql.gz");
//add your content here
$content = file_get_contents("/tmp/test.sql");
$status = $FileCompressionHandler->write($content);
$FileCompressionHandler->close();
echo $status ? "Compressed!" : "Error!";include "lib/compression/ZipHandler.php";
//zip folder
$status = ZipHandler::zip("/tmp/my_folder_to_zip", "/tmp/zipped_file.zip");
//rename files inside of zip
$to_replace = "old/folder/path/";
$replacement = "my/new/folder/";
$status = ZipHandler::renameFileInZip("/tmp/zipped_file.zip", $to_replace, $replacement)
//add file/folder to an existing zip file
$status = ZipHandler::addFileToZip("/tmp/zipped_file.zip", "/tmp/another_folder/", "/internal/zip/folder/path/");
//unzip file to "/tmp/test/" folder
$status = ZipHandler::unzip("/tmp/zipped_file.zip", "/tmp/test/");