js/php Get Flash Width Instance code

Source: Internet
Author: User
Tags ord php code strlen


Js:

Setting the embed height and width can change the height and width of the flash, thereby gaining.

The code is as follows Copy Code


<! DOCTYPE html>
<body>

<embed src= "test550x400.swf" id= "Flash" width= "550px" height= "400px"/>
<script type= "Text/javascript" >
var flash = document.getElementById ("flash");
Alert ("Wide:" +flash.width+ "High:" +flash.height);
</script>
</body>


PHP code

The code is as follows Copy Code

<?php
/*
Example:
$file = '/data/ad_files/5/5.swf ';
$flash = new Flash ();
$flash = $flash->getswfinfo ($file);
echo "
The height of the file is: ". $flash [" width]. ". $info [" height "];
echo "
The file version is ". $flash [" Version "];
echo "
The number of file frames is ". $flash [" Framecount "];
echo "
The file frame rate is ". $flash [" framerate "];
echo "
The file background color is ". $flash [" bgcolor "];
*/
Class Flash
{
Whether to return a background color
Public $need _back_color = false;

Whether to return version
Public $need _version = false;

Whether to return the frame rate
Public $need _framerate = false;

Whether to return the number of frames
Public $need _framecount = false;

Public Function __construct ()
{

}

Public Function Getswfinfo ($filename)
{
if (file_exists ($filename)) {
echo "File modification Time:". Date ("M d y h:i:s.", Filemtime ($filename)). "
";
} else {
echo "Destination file does not exist!";
Return Array ("error" => $filename);
}

   //Open file
    $rs = fopen ($filename, "R");
   
     read data for file
    $str = fread ($rs, FileSize ($filename));
   ///
    if ($str [0] = = "F")
    {
      //echo
File is already uncompressed file: ";
   } else {
       $first = substr ($str, 0,8);
  & nbsp;    $last = substr ($STR, 8);
      //
       $last = gzuncompress ($last);
      //
       $str = $first. $last;
        $str [0] = "f";
      //echo
Uncompressed file information: ";
   }

$info = $this->getinfo ($STR);
Fclose ($RS);
return $info;
}

Private Function Mydecbin ($STR, $index)
{
$fbin = Decbin (Ord ($str [$index]));
while (strlen ($fbin) <8) $fbin = "0". $fbin;
return $fbin;
}

Private Function Colorhex ($data)
{
$tmp = Dechex ($data);
if (strlen ($tmp) <2) {
$tmp = ' 0 '. $tmp;
}
return $tmp;
}

Private Function GetInfo ($STR)
{
Converted into binary
$fbin = $this->mydecbin ($str, 8);

Calculate the unit length of rec
$slen = Bindec (substr ($fbin, 0, 5));

Calculate the bytes in which the Rec is located
$recsize = $slen * 4 + 5;
$recsize = Ceil ($recsize/8);

Rec Binary
$recbin = $fbin;
for ($i = 9; $i < $recsize + 8; $i + +)
{
$recbin. = $this->mydecbin ($str, $i);
}

REC Data
$rec = Array ();
for ($i = 0; $i < 4; $i + +)
{
$rec [] = Bindec (substr ($recbin, 5 + $i * $slen, $slen))/20;
}

if ($this->need_back_color) {
Background color
for ($i = $recsize + $i < strlen ($STR); $i + +)
{
if (Ord ($str [$i]) = = && Ord ($str [$i +1]) = = 2)
{
$bgcolor = $this->colorhex (ord ($str [$i +2]). $this->colorhex (Ord ($str [$i +3])). $this->colorhex (Ord ($str [$ I+4]));
Break
}
}
}

if ($this->need_version) {
Version
$version = Ord ($str [3]);
}
if ($this->need_framerate) {
Frame rate
$framerate = Ord ($str [$recsize + 8])/256 + ord ($str [$recsize + 9]);
}

if ($this->need_framecount) {
Number of Frames
$framecount = Ord ($str [$recsize +]) * 256 + ord ($str [$recsize + 10]);
}

Return Array ("bgcolor" => $bgcolor,
"Version" => $version,
"Framerate" => $framerate,
"Framecount" => $framecount,
' Width ' => $rec [1],
' Height ' => $rec [3]
);
}
}

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.