PHP zlib Code _php Tutorial for compressing and decompressing swf files

Source: Internet
Author: User
Tags fread
PHP is not the same, PHP contains the zlib link library, you can directly use its related functions, the following is the example I wrote compression and compressed SWF file:
Not added to determine whether the SWF file has been compressed, into the need can be based on the first byte of a file is ' F ' or ' C ' to determine
To compress a SWF file:
//--------------------------------------------------------------------------------------------------
Filename
$filename = "test.swf";
Open File
$rs = fopen ($filename, "R");
Reading data from a file
$str = Fread ($rs, FileSize ($filename));
Set SWF header File
$head = substr ($str, 1,8);
$head = "C". $head;
Get SWF file contents
$body = substr ($STR, 8);
Compress the contents of a file using the highest compression level 9
$body = Gzcompress ($body, 9);
Merging file headers and contents
$str = $head. $body;
Close the Read file stream
Fclose ($RS);
Create a new file
$ws = fopen ("create.swf", "w");
Write a file
Fwrite ($ws, $STR);
Close file leave
Fclose ($WS);
//----------------------------------------------------------------------------------------------------
?>
To extract the SWF file:
//----------------------------------------------------------------------------------------------------
Filename
$filename = "test.swf";
Open File
$rs = fopen ($filename, "R");
Reading data from a file
$str = Fread ($rs, FileSize ($filename));
Set SWF header File
$head = substr ($str, 1,8);
$head = "F". $head;
Get SWF file contents
$body = substr ($STR, 8);
Unzip the contents of a file
$body = gzuncompress ($body);
Merging file headers and contents
$str = $head. $body;
Close the Read file stream
Fclose ($RS);
Create a new file
$ws = fopen ("create.swf", "w");
Write a file
Fwrite ($ws, $STR);
Close file leave
Fclose ($WS);
//----------------------------------------------------------------------------------------------------
?>
How's it going? Oh, PHP gives us more than simply "'

http://www.bkjia.com/PHPjc/319856.html www.bkjia.com true http://www.bkjia.com/PHPjc/319856.html techarticle using PHP is not the same, PHP contains the zlib link library, you can directly use its related functions, the following is my writing compression and compressed SWF file example://Not added to determine whether the SWF file has ...

  • 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.