Before we use the zlip function, we need to perform the following operations, otherwise we will not be able to read it down.
First set in PHP. ini
| The code is as follows: |
Copy code |
|
Zlib. output_compression = On
Zlib. output_compression_level = 6 |
The first option is enable compression, and the second option is compression ratio. The optional range is 1-9;
Then enable deflate compression in apach to remove the well number.
| The code is as follows: |
Copy code |
|
# LoadModule deflate_module modules/mod_deflate.so |
So far, this still does not work. You also need to select a blank area in http. conf and add the output filter of the file type to select which suffixes to press.
.
| The code is as follows: |
Copy code |
|
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js txt php xml html htm |
If you do not have the permission to modify the php. Ini file, you can use the phpr ini_set function to perform operations.
For example
| The code is as follows: |
Copy code |
|
<? Php
Ini_set ("zlib. output_compression", "On ");
?>
<? Php
Ini_set ("zlib. output_compression", 4096 );
?>
|
Okay, now everything is ready for us to import the final file.
Compress the swf file:
| The code is as follows: |
Copy code |
|
<? Php
// File name
$ Filename = "test.swf ";
// Open the file
$ Rs = fopen ($ filename, "r ");
// Read the file data
$ Str = fread ($ rs, filesize ($ filename ));
// Set the swf header file
$ Head = substr ($ str, 1, 8 );
$ Head = "C". $ head;
// Obtain the swf file content
$ Body = substr ($ str, 8 );
// Compress the file content with a maximum compression level of 9
$ Body = gzcompress ($ body, 9 );
// Merge the file header and content
$ Str = $ head. $ body;
// Close the read File Stream
Fclose ($ rs );
// Create a new file
$ Ws = fopen ("create.swf", "w ");
// Write an object
Fwrite ($ ws, $ str );
// Close File retention
Fclose ($ ws );
?>
Decompress the flash swf file
// File name
$ Filename = "test.swf ";
// Open the file
$ Rs = fopen ($ filename, "r ");
// Read the file data
$ Str = fread ($ rs, filesize ($ filename ));
// Set the swf header file
$ Head = substr ($ str, 1, 8 );
$ Head = "F". $ head;
// Obtain the swf file content
$ Body = substr ($ str, 8 );
// Decompress the file content
$ Body = gzuncompress ($ body );
// Merge the file header and content
$ Str = $ head. $ body;
// Close the read File Stream
Fclose ($ rs );
// Create a new file
$ Ws = fopen ("create.swf", "w ");
// Write an object
Fwrite ($ ws, $ str );
// Close File retention
Fclose ($ ws );
?> |
Note: The gzip data header is larger than the zlib data header because it stores file names and other file system information. In fact, this is a widely used gzip file
Data header format. Note that the zlib library itself cannot create a gzip file, but it is quite easy to write compressed data to a gzip file.
.