Skip to content

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.

License

Unknown and 3 other licenses found

Licenses found

Unknown
LICENSE.md
Apache-2.0
LICENSE_APACHE_2.md
BSD-3-Clause
LICENSE_BSD_3C.md
LGPL-3.0
LICENSE_GNU_LGPL_3.md
Notifications You must be signed in to change notification settings

a19836/phpcompressionlib

PHP Compression Lib

Original Repos:

Overview

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.


Usage:

Compress Content:

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

Compress File:

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

Handling ZIP files

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/");

About

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.

Topics

Resources

License

Unknown and 3 other licenses found

Licenses found

Unknown
LICENSE.md
Apache-2.0
LICENSE_APACHE_2.md
BSD-3-Clause
LICENSE_BSD_3C.md
LGPL-3.0
LICENSE_GNU_LGPL_3.md

Stars

Watchers

Forks

Packages

No packages published

Languages