-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
105 lines (85 loc) · 3.57 KB
/
index.php
File metadata and controls
105 lines (85 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/*
* Copyright (c) 2025 Bloxtor (http://bloxtor.com) and Joao Pinto (http://jplpinto.com)
*
* Multi-licensed: BSD 3-Clause | Apache 2.0 | GNU LGPL v3 | HLNC License (http://bloxtor.com/LICENSE_HLNC.md)
* Choose one license that best fits your needs.
*
* Original PHP Compression Lib Repo: https://github.com/a19836/php-compression-lib/
* Original Bloxtor Repo: https://github.com/a19836/bloxtor
*
* YOU ARE NOT AUTHORIZED TO MODIFY OR REMOVE ANY PART OF THIS NOTICE!
*/
?>
<style>
h1 {margin-bottom:0; text-align:center;}
h5 {font-size:1em; margin:40px 0 0; font-weight:bold;}
p {margin:0 0 20px; text-align:center;}
.note {text-align:center;}
.note span {text-align:center; margin:0 20px 20px; padding:10px; color:#aaa; border:1px solid #ccc; background:#eee; display:inline-block; border-radius:3px;}
.code {display:block; margin:10px 0; padding:0; background:#eee; border:1px solid #ccc; border-radius:3px; position:relative;}
.code:before {content:"php"; position:absolute; top:5px; left:5px; display:block; font-size:80%; opacity:.5;}
.code textarea {width:100%; height:300px; padding:30px 10px 10px; display:inline-block; background:transparent; border:0; resize:vertical; font-family:monospace;}
</style>
<h1>PHP Compression Lib</h1>
<p>Compress files or content</p>
<div class="note">
<span>
This library allows you to compress files or raw content using multiple compression formats, including bzip2, gzip, gzipstream, and ZIP.<br/>
In addition, it provides utilities to read, modify, and manage '.zip' archives programmatically.
</span>
</div>
<div>
<h5>Compress Content:</h5>
<div class="code">
<textarea readonly>
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!";
</textarea>
</div>
</div>
<div>
<h5>Compress File:</h5>
<div class="code">
<textarea readonly>
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!";
</textarea>
</div>
</div>
<div>
<h5>Handling ZIP files</h5>
<div class="code">
<textarea readonly>
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/");
</textarea>
</div>
</div>