我在以前写过怎么使用c#来压缩和解压缩swf文件,解压缩,压缩和读取flash头文件信息需要使用一个开源的链接库,而且使用起来也不是很方便,但是使用php就不一样了,php包含了zlib的链接库,可以直接使用其相关功能,下面是我写的压缩和结压缩swf文件的例子,没有加入判定swf文件是否已经压缩,入需要可以根据文件的第一个字节是'F'或者'C'来判定,压缩swf文件:
- <?php
-
-
- $filename = "test.swf";
-
- $rs = fopen($filename,"r");
-
- $str = fread($rs,filesize($filename));
-
- $head = substr($str,1,8);
- $head = "C".$head;
-
- $body = substr($str,8);
-
- $body = gzcompress($body, 9);
-
- $str = $head.$body;
-
- fclose($rs);
-
- $ws = fopen("create.swf","w");
-
- fwrite($ws,$str);
-
- fclose($ws);
-
- ?>
解压缩swf文件:
- <?php
-
-
- $filename = "test.swf";
-
- $rs = fopen($filename,"r");
-
- $str = fread($rs,filesize($filename));
-
- $head = substr($str,1,8);
- $head = "F".$head;
-
- $body = substr($str,8);
-
- $body = gzuncompress($body);
-
- $str = $head.$body;
-
- fclose($rs);
-
- $ws = fopen("create.swf","w");
-
- fwrite($ws,$str);
-
- fclose($ws);
-
- ?>
怎么样?是不是很简单?呵呵,php给我们的不止是简单... |