Phpzlib: code for compressing and decompressing swf files _ PHP Tutorial

Source: Internet
Author: User
Phpzlib compresses and decompress the swf file code. Php contains the zlib link Library, which can be used directly. The following is an example of my compressed and compressed swf files: it is different if the swf file has been used in php without being added. php contains the zlib link library and can directly use its functions, the following is an example of my compressed and compressed swf files:
// If the swf file is not compressed, the first byte of the file is 'F' or 'C '.
Compress the swf file:
// 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 );
// 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 );
// Configure //----------------------------------------------------------------------------------------------------
?>
Decompress the swf file:
// 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 );
// Close File retention
Fclose ($ ws );
// Configure //----------------------------------------------------------------------------------------------------
?>
How is it? Is it easy? Haha, php not only gives us simple "'

Else // not added to determine whether the swf file is already...

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.