Home > Article > Backend Development > Compress and decompress swf files using php's zlib_PHP tutorial
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);
//------------------------- -------------------------------------------------- --------------------------
?>