Use php zlib to compress and decompress swf file _ PHP Tutorial

Source: Internet
Author: User
Use php zlib to compress and decompress the swf file. The following example shows how to compress and compress a swf File. if the swf file is not compressed, the first byte of the file is F or C to compress the swf file. The following is an example of my compress and compress the swf file:

// If the swf file is not compressed, the first byte of the file is F or C.

Compress the 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 = "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 );
// ------ Http://soft.knowsky.com/Workshop /----------------------------------------------------------------------------------------------
?>
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 //----------------------------------------------------------------------------------------------------
?>

Else // if the swf file is not compressed, you can determine whether to compress the swf file based on the first byte of the file F or C...

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.