php解压swf

<?php  
//文件名
filename = "test.swf";
//打开文件rs = fopen(filename,"r");
//读取文件的数据str = fread(rs,filesize(filename));
//check compress status
check = substr(str,0,1);
if(check=="C")
{
	echo "这是一个压缩文件,下面解压";
//设置swf头文件head = substr(str,1,7);head = "F".head;
//获取swf文件内容body = substr(str,8);
//解压缩文件内容body = gzuncompress(body);
//合并文件头和内容str = head.body;
//关闭读取的文件流
fclose(rs);
//创建一个新的文件ws = fopen("jieya.swf","w");
//写文件
fwrite(ws,str);
}else if(check=="F")
{
	echo "这是一个没有压缩的文件,下面开始压缩";head = substr(str,1,7);head = "C".head;body = substr(str,8);body = gzcompress(body, 9);str = head.body; 
fclose(rs);ws = fopen("yasuo.swf","w");  
fwrite(ws,str);  
}else
{
  echo "这不是一个合法的flash文件";
}
//关闭文件
fclose($ws);
?>

php通过ming扩展创建swf经典范例

1.画个正方形

<?php
mc = new SWFMovie();mc->setDimension( 200, 200 );

s = new SWFShape();s->setLine( 5, 0, 0, 0 );
s->movePenTo( 20, 20 );s->drawLineTo( 160, 20 );
s->drawLineTo( 160, 160 );s->drawLineTo( 20, 160 );
s->drawLineTo( 20, 20 );mc->add( s );mc->save( 'shape.swf' );
?>

2.合并jpg图片

<?php
   m = new SWFMovie();m->setDimension(200, 200);
  m->add(new SWFBitmap(fopen("s.jpg", "rb")));

  //header('Content-type: application/x-shockwave-flash');m->save( 'shape4.swf' );
?>

3.外部加载swf

<?php
    m = new SWFMovie();m->setRate(30.000000);
    m->setDimension(200, 200);m->setBackground(0xff, 0xff, 0xff);

    m->add(new SWFAction('
        myvar = "variable to pass to flash";
        LoadMovie("shape4.swf", "mc");
    '));

    /* -- make movie clip 'mc' that we will load flash_file_created_by_hand.swf into -- */s1 = new SWFSprite();  /* (1 frames) */
    s1->nextFrame();  /* (end of sprite frame 0) */i1 = m->add(s1);
    i1->setName('mc');m->nextFrame();  /* (end of frame 0) */

    //header('Content-type: application/x-shockwave-flash');
   // m->output();m->save("1.swf");
?>

4.合并swf,(注意这里的swf都是非压缩的,要合并压缩的swf,先要解压缩然后再压缩,参考这篇文章:php解压swf)

<?php
   m = new SWFMovie();m->setDimension(200, 200);
  m->add(new SWFPrebuiltClip(fopen("shape4.swf", "rb")));m->add(new SWFPrebuiltClip(fopen("shape.swf", "rb")));
  //header('Content-type: application/x-shockwave-flash');
  $m->save( 'ms.swf' );
?>