if there are some flash functions in php....

解决方案 »

  1.   

    呵呵……
    应该是可以实现的
    swf文件格式规范是公开的,可以上adobe的网站上看一看
    直接对swf文件进行解析,应该在固定的地址上可以找到相关值的
    没有深入研究过swf文件格式
      

  2.   

    给出swf文件格式说明中的一部分说明吧,等改天有时间和精力,写个逻辑试试看。
    ========================================
    The SWF header
    All SWF files begin with the following header. The types are defined in Basic Data Types:
    SWF File Header
    Field Type Comment
    Signature UI8 Signature byte:
    “F” indicates uncompressed
    “C” indicates compressed (SWF 6 and later only)
    Signature UI8 Signature byte always “W”
    Signature UI8 Signature byte always “S”
    Version UI8 Single byte file version (for example, 0x06 for SWF 6)
    FileLength UI32 Length of entire file in bytes
    FrameSize RECT Frame size in twips
    FrameRate UI16 Frame delay in 8.8 fixed number of frames per second
    FrameCount UI16 Total number of frames in file
    SWF file structure 17
    The header begins with a three-byte signature of either 0x46, 0x57, 0x53 (“FWS”); or 0x43,
    0x57, 0x53 (“CWS”). An FWS signature indicates an uncompressed SWF file; CWS
    indicates that the entire file after the first 8 bytes (that is, after the FileLength field) was
    compressed by using the ZLIB open standard. The data format that the ZLIB library uses is
    described by Request for Comments (RFCs) documents 1950 to 1952. CWS file compression
    is permitted in SWF 6 or later only.
    A one-byte version number follows the signature. The version number is not an ASCII
    character, but an 8-bit number. For example, for SWF 4, the version byte is 0x04, not the
    ASCII character “4” (0x35).
    The FileLength field is the total length of the SWF file, including the header. If this is an
    uncompressed SWF file (FWS signature), the FileLength field should exactly match the file
    size. If this is a compressed SWF file (CWS signature), the FileLength field indicates the total
    length of the file after decompression, and thus generally does not match the file size. Having
    the uncompressed size available can make the decompression process more efficient.
    The FrameSize field defines the width and height of the on-screen display. This field is stored
    as a RECT structure, meaning that its size may vary according to the number of bits needed
    to encode the coordinates. The FrameSize RECT always has Xmin and Ymin of 0; the Xmax
    and Ymax members define the width and height (see Using bit values).
    The FrameRate is the desired playback rate in frames per second. This rate is not guaranteed
    if, for example, Flash Player is running on a slow or busy CPU.
    The FrameCount is the total number of frames in this SWF file.
      

  3.   

    最近研究了一下swf文件格式,尝试着写了一个类。详细说明见 http://listen2rain.co.nr.zogola.net/?entry=13
    或 http://blog.csdn.net/peterdoo/archive/2006/07/07/890749.aspx现给出代码如下:// swfHeaderParse.php
    <?php
    /**
     * @author PeterDoo
     * @version 1.0
     */
    class swfHeaderParser {
    var $swf = null; // swf文件指针
    var $swfHeader = null; // swf文件头
    var $compress = "Unknow"; // swf文件压缩状态
    var $version = "Unknow"; // swf文件版本
    var $size = "Unknow"; // swf文件大小
    var $frameRate = "Unknow"; // swf文件帧频
    var $frameTotal = "Unknow"; // swf文件帧数

    /**
     * 构造函数
     * @param string $file swf文件名
     */
    function swfHeaderParser($file = '') {
    if (!empty($file)) {
    $this->initSWFHeader($file);
    }
    }

    /**
     * 初始化解析器swf文件头
     * @param string $file swf文件名
     * @return boolean
     * @access private
     */
    function initSWFHeader($file) {
    $fmt = strtolower(substr($file, strpos($file, '.') + 1));

    if ($fmt == 'swf') {
    $this->swf = @fopen($file, 'rb');

    if (!$this->swf) {
    die("打开文件失败");
    }

    $sign = fread($this->swf, 3);

    if (!($sign == "FWS" || $sign == "CWS")) {
    @fclose($this->swf);
    die("文件格式错误");
    } else {
    if ($sign[0] == 'C') {
    if (function_exists("gzuncompress")) {
    fseek($this->swf, 4);

    $len = fread($this->swf, 4);
    $len = strrev($len);
    $len = hexdec(bin2hex($len));

    $buffer = fread($this->swf, $len);
    $buffer = gzuncompress($buffer, $len);

    fseek($this->swf, 0);

    $header = fread($this->swf, 8);
    $header .= substr($buffer, 0, 20);

    $this->swfHeader = $header;
    } else {
    @fclose($this->swf);
    die("该swf文件采用了压缩格式,但您的php不支持压缩处理");
    }
    } else if ($sign[0] == 'F') {
    fseek($this->swf, 0);
    $this->swfHeader = fread($this->swf, 28);
    } else {
    @fclose($this->swf);
    die("未知文件格式");
    }

    @fclose($this->swf);
    return true;
    }
    } else {
    die("文件格式错误");
    }
    }

    /**
     * 获取swf文件压缩标识
     * @return string
     */
    function getCompressFlag() {
    switch ($this->swfHeader[0]) {
    case 'F':
    $this->compress = "Uncompressed";
    break;
    case 'C':
    $this->compress = "Compressed";
    break;
    }

    return $this->compress;
    }

    /**
     * 获取swf文件版本
     * @return number
     */
    function getVersion() {
    $this->version = ord($this->swfHeader[3]);
    return $this->version;
    }

    /**
     * 获取swf文件大小
     * @return string
     */
    function getSize() {
    $sum = strrev(substr($this->swfHeader, 4, 4));

    $sum = hexdec(bin2hex($sum));

    $this->size = $sum . ' bytes(Uncompressed)';

    return $this->size;
    }

    /**
     * 获取swf文件头中RECT结构结束位置
     * @return number
     */
    function getRECTEnd() {
    $Nbits = ord($this->swfHeader[8]);

    $Nbits >>= 3;

    $len = ceil((($Nbits * 4) - 3) / 8);

    $offset = 8 + $len;

    return $offset;
    }

    /**
     * 获取播放窗口大小
     * @return array 第一元素表示宽,第二元素表示高
     */
    function getScreen() {
    $Nbits = ord($this->swfHeader[8]);

    $Nbits >>= 3;

    $seg_len = $this->getRECTEnd() - 8;

    $str = substr($this->swfHeader, 8, $seg_len);

    $str_len = strlen($str);

    $bin_str = '';

    for ($i = 0; $i < $str_len; $i++) {
    for ($j = 7; $j >= 0; $j--) {
    $cur_byte = ord($str[$i]);
    $cur_byte >>= $j;
    $bin_str .= ($cur_byte & 1);
    }
    }

    for ($i = 0; $i < 4; $i++) {
    $cur_bitval = substr($bin_str, 5 + $Nbits * $i, $Nbits);
    $val = 0;

    for ($j = 0; $j < $Nbits; $j++) {
    $s = 0;

    if ((int)$cur_bitval[$j]) {
    $s = 1;

    for ($k = 0;$k < $Nbits - $j - 1; $k++) {
    $s *= 2;
    }
    }

    $val += $s;
    }

    $tmp[$i] = $val / 20;
    }

    $screen[0] = $tmp[1] - $tmp[0];
    $screen[1] = $tmp[3] - $tmp[2];

    return $screen;
    }

    /**
     * 获取swf文件帧频
     * @return string
     */
    function getFrameRate() {
    $offset = $this->getRECTEnd() + 1;

    $rate = strrev(substr($this->swfHeader, $offset, 2));

    $r1 = ord($rate[0]);

    $r2 = bin2hex($rate[1]);

    $r2 = ($r2[0] / 16) + ($rs[1] / (16 * 16));

    $rate = $r1 + $r2;

    $this->frameRate = $rate . "fps";

    return $this->frameRate;
    }

    /**
     * 获取swf文件帧数
     * @return number
     */
    function getFrameTotal() {
    $offset = $this->getRECTEnd() + 1;

    $total = strrev(substr($this->swfHeader, $offset + 2, 2));

    $total = hexdec(bin2hex($total));

    $this->frameTotal = $total;

    return $this->frameTotal;
    }
    }
    ?>// demo.php
    <?php
    require_once "swfHeaderParser.php";$shp = new swfHeaderParser('preview.swf');echo "<b>Compressed state:</b> " . $shp->getCompressFlag();
    echo "<br>";
    echo "<b>Version:</b> " . $shp->getVersion();
    echo "<br>";
    echo "<b>Size:</b> " . $shp->getSize();
    echo "<br>";
    $screen = $shp->getScreen();
    echo "<b>Width:</b> " . $screen[0] . " pix; <b>Height:</b> " . $screen[1] . " pix";
    echo "<br>";
    echo "<b>Frame rate:</b> " . $shp->getFrameRate();
    echo "<br>";
    echo "<b>Frame total:</b> " . $shp->getFrameTotal();
    ?>
      

  4.   

    You can see the ming functions in PHP manual.
      

  5.   

    php有flash扩展函数库——php_ming
    你可以用一下
      

  6.   

    文件头里面就有,不过如果是压缩过的需要解压缩。Zlib压缩方式。
      

  7.   

    最近看到flash的js API,里面有。