当前位置:主页>FLASH AS 编程>AS高手篇>文章内容
  • 通过PHP读取Flash文件的头部信息
  • 来源:世纪流年Blog站 作者:Liu21st 2006-07-02 【
FlashAs作品发表>>我要投稿 | FlashAs讨论区>>AS论坛
Flash Media Server学习站>>www.FMScn.com


非常棒的一个方法,使用php程序可以读取swf文件的头部信息,如大小、播放版本、播放速率、帧数和舞台大小等,似乎可以在以后的blog程序中自动获取swf文件的大小而不用手动设定大小了。
引用地址:http://www.sephiroth.it
程序实现如下:
<?php
/**
* Flash Header reader
* Alessandro Crugnola (sephiroth)
* alessandro@sephiroth.it
* http://www.sephiroth.it

* Read the SWF header informations and return an 
* associative array with the property of the SWF File
*
* @param input string file
* @returns array
*
*
* How to use
* -------------------------------------
* $f = new FlashHeader("flash.swf");
* $result = $f->getimagesize();
* print_r($result);
* -------------------------------------
*
*/
class FlashHeader{
    var $version;
    var $filetype;
    var $bitpos;
    var $cur;
    var $pos;
    var $rect;
    var $framerate;
    var $length;
    var $compression = 0;
    var $point = 0;
    var $isValid = 0;
    /**
    * @method FlashHeader 
    * @type constructor 
    * @param string file
    */
    function FlashHeader($buffer){
        $this->buffer = $buffer;
        $fp = @fopen($this->buffer,"rb");
        $head = @fread($fp, 3);
        if($head == "CWS"){
            /* zlib */
            fseek($fp,0);
            $data = fread($fp,8);
非常棒的一个方法,使用php程序可以读取swf文件的头部信息,如大小、播放版本、
播放速率、帧数和舞台大小等,似乎可以在以后的blog程序中自动获取swf文件的大小而不用手动设
定大小了。
引用地址:http://www.sephiroth.it
程序实现如下:
___FCKpd___0
data = gzuncompress(fread($fp, filesize($buffer)));
            $data = $data . 非常棒的一个方法,使用php程序可以读取swf文件的头部信息,
如大小、播放版本、播放速率、帧数和舞台大小等,似乎可以在以后的blog程序中自动获取swf文件
的大小而不用手动设定大小了。
引用地址:http://www.sephiroth.it
程序实现如下:
___FCKpd___0
data;
            $this->data = $data;
            $this->compression = 1;
            $this->isValid = 1;
        } else if ($head == "FWS"){
            fseek($fp,0);
            $this->data = fread($fp, filesize($buffer));
            $this->isValid = 1;
        } else {
            $this->isValid = 0;
        }
        @fclose($fp);
    }
    
    /**
    * @method getimagesize
    * @type public
    * @description read the file informations
    */
    function getimagesize(){
        if(!$this->isValid){
            return false;
        }
        $this->filetype = $this->read(3);
        $this->version =  $this->readbyte();
        $l = $this->read(4);
        $this->filelength = filesize($this->buffer);
        $this->rect = $this->readRect();
        $this->framerate = unpack(’vrate’,$this->read(2));
        $this->framerate = $this->framerate[’rate’]/256;
        $this->framecount = $this->readshort();
        return array(    
                        "zlib-compression"=> $this->compression, 
                        "fileType" => $this->filetype, 
                        "version" => $this->version,
                        "fileSize" => $this->filelength,
                        "frameRate" => $this->framerate,
                        "frameCount" => $this->framecount,
                        "movieSize" => $this->rect
                    );
    }
    
    /* read */
    function read($n){
        $ret = substr($this->data, $this->point, $this->point + $n);
        $this->point += $n;
        return $ret;
    }    
    
    /* read short */
    function readshort(){
        $pack = unpack(’vshort’,$this->read(2));
        return $pack[’short’];
    }
    
    /* read byte */
    function readByte(){
        $ret = unpack("Cbyte",$this->read(1));
        return $ret[’byte’];
    }
    /* read Rect */
    function readRect(){
        $this->begin();
        $l = $this->readbits(5);
        $xmin = $this->readbits($l)/20;
        $xmax = $this->readbits($l)/20;
        $ymin = $this->readbits($l)/20;
        $ymax = $this->readbits($l)/20;
        $rect = new Rect($xmax, $ymax);
        return $rect->__str__();
    }
    /* incpos */
    function incpos(){
        $this->pos += 1;
        if($this->pos>8){
            $this->pos = 1;
            $this->cur = $this->readbyte();
        }
    }    
    
    
    /* readbits */
    function readbits($nbits){
        $n = 0;
        $r = 0;
        while($n < $nbits){
            $r = ($r<<1) + $this->getbits($this->pos);
            $this->incpos();
            $n += 1;
        }
        return $r;
    }
    
    /* getbits */
    function getbits($n){
        return ($this->cur>>(8-$n))&1;
    }
    
    /* begin */
    function begin(){
        $this->cur = $this->readbyte();
        $this->pos = 1;
    }
    
}

/**
* class Rect
* store the size values into an associative array
*/
class Rect{
    function Rect($x2,$y2){
        $this->xmax = $x2;
        $this->ymax = $y2;
        $this->value = $this->__str__();
    }
    function __str__(){
        $ret = array($this->xmax, $this->ymax);
        $ret["width"] = $this->xmax;
        $ret["height"] = $this->ymax;
        return $ret;
    }
}
/* end */
?>




上一篇:AS2 Class: detachShowData   下一篇:一个最基本的WebService+Flash调用的实例
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)