php zlib压缩和解压缩swf文件的代码_PHP教程

WBOY
Release: 2016-07-21 15:47:49
Original
891 people have browsed it

使用php就不一样了,php包含了zlib的链接库,可以直接使用其相关功能,下面是我写的压缩和结压缩swf文件的例子:
//没有加入判断swf文件是否已经压缩,入需要可以根据文件的第一个字节是'F'或者'C'来判断
压缩swf文件:
//--------------------------------------------------------------------------------------------------
//文件名
$filename = "test.swf";
//打开文件
$rs = fopen($filename,"r");
//读取文件的数据
$str = fread($rs,filesize($filename));
//设置swf头文件
$head = substr($str,1,8);
$head = "C".$head;
//获取swf文件内容
$body = substr($str,8);
//压缩文件内容,使用最高压缩级别9
$body = gzcompress($body, 9);
//合并文件头和内容
$str = $head.$body;
//关闭读取的文件流
fclose($rs);
//创建一个新的文件
$ws = fopen("create.swf","w");
//写文件
fwrite($ws,$str);
//关闭文件留
fclose($ws);
//----------------------------------------------------------------------------------------------------
?>
解压缩swf文件:
//----------------------------------------------------------------------------------------------------
//文件名
$filename = "test.swf";
//打开文件
$rs = fopen($filename,"r");
//读取文件的数据
$str = fread($rs,filesize($filename));
//设置swf头文件
$head = substr($str,1,8);
$head = "F".$head;
//获取swf文件内容
$body = substr($str,8);
//解压缩文件内容
$body = gzuncompress($body);
//合并文件头和内容
$str = $head.$body;
//关闭读取的文件流
fclose($rs);
//创建一个新的文件
$ws = fopen("create.swf","w");
//写文件
fwrite($ws,$str);
//关闭文件留
fclose($ws);
//----------------------------------------------------------------------------------------------------
?>
怎么样?是不是很简单?呵呵,php给我们的不止是简单“`

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319856.htmlTechArticle使用php就不一样了,php包含了zlib的链接库,可以直接使用其相关功能,下面是我写的压缩和结压缩swf文件的例子: //没有加入判断swf文件是否已经...
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!