Use zlib of php to compress and decompress swf files

Source: Internet
Author: User
Tags what php
I have previously written how to apply c # to compress and decompress swf files, decompress, compress, and read flash header file information. an open source link Library is required, and the application is not very convenient, but the application of php is different. php contains the link library of zlib, which can be directly applied to its coherence function, the following is an example of how to use c # to compress and decompress a swf file, to compress and read flash header file information, you need to apply an open-source link Library, which is not very convenient, but php is different. php contains the zlib link Library, you can directly apply the relevant functions. The following is an example of my compress and compress swf files:

// Failed to determine whether the swf file has been compressed. you can determine whether the first byte of the file is 'F' or 'C '.


Compress the swf file:

<? Php
// Configure //--------------------------------------------------------------------------------------------------
// 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 );
// Compresses the file content. The maximum application compression level is 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 );
// Keep closed files
Fclose ($ ws );
// Configure //----------------------------------------------------------------------------------------------------
?>
Decompress the swf file:

<? Php
// Configure //----------------------------------------------------------------------------------------------------
// 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 );
// Keep closed files
Fclose ($ ws );
// Configure //----------------------------------------------------------------------------------------------------
?>

How is it? Is it very simple? What php gives us is not just a brief introduction...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.