Compress and decompress swf files using php's zlib_PHP tutorial

WBOY
Release: 2016-07-13 17:31:57
Original
749 people have browsed it

The following is an example of compressing and uncompressing swf files I wrote:

// There is no addition to determine whether the swf file has been compressed. If necessary, you can determine whether the first byte of the file is F or C. Determine

Compressed swf file: //File name
$filename = "test.swf";
//Open file
$rs = fopen($filename,"r");
//Read file data
$str = fread($rs,filesize($filename));
//Set swf header file
$head = substr($str,1, 8);
$head = "C".$head;
//Get the swf file content
$body = substr($str,8);
//Compress the file content, use the highest Compression level 9
 $body = gzcompress($body, 9);
 //Merge file header and content
 $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 the file and leave it
 fclose($ws);
 //------http://soft.knowsky.com/----- -------------------------------------------------- ---------------------------------------
 ?>
 Unzip swf file:
 
  //--------------------------------------------- -------------------------------------------------- -----------
 //File name
 $filename = "test.swf";
 //Open file
 $rs = fopen($filename,"r ");
 //Read file data
 $str = fread($rs,filesize($filename));
 //Set swf header file
 $head = substr($str ,1,8);
 $head = "F".$head;
 //Get the swf file content
 $body = substr($str,8);
 //Unzip the file Content
 $body = gzuncompress($body);
 //Merge file header and content
 $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 the file and leave it
 fclose($ws);
 //------------------------- -------------------------------------------------- --------------------------
 ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508903.htmlTechArticleThe following is an example of compressing and uncompressing swf files I wrote: //No judgment is added to determine whether the swf file has been compressed , if necessary, you can judge the compressed swf file according to whether the first byte of the file is F or C...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!