PHP read the Flash file high-wide frame number background color method,
This paper describes the method of PHP reading the background color of high-wide frame number of Flash file. Share to everyone for your reference.
The implementation method is as follows:
Copy CodeThe code is as follows: <?php
/*
Example:
$file = '/data/ad_files/5/5.swf ';
$flash = new Flash ();
$flash = $flash->getswfinfo ($file);
echo "
The width 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 the background color
Public $need _back_color = false;
Whether to return version
Public $need _version = false;
Whether to return 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");
Reading data from a file
$str = Fread ($rs, FileSize ($filename));
///
if ($str [0] = = "F")
{
echo "
The file is already uncompressed: ";
} else {
$first = substr ($str, 0,8);
$last = substr ($STR, 8);
//
$last = gzuncompress ($last);
//
$str = $first. $last;
$str [0] = "f";
echo "
Extracted 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)
{
Conversion into binary
$fbin = $this->mydecbin ($str, 8);
Calculates the unit length of rec
$slen = Bindec (substr ($fbin, 0, 5));
Calculate the byte of rec
$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])/+ + ord ($str [$recsize + 9]);
}
if ($this->need_framecount) {
Number of Frames
$framecount = Ord ($str [$recsize + one]) * + ord ($str [$recsize + 10]);
}
Return Array ("bgcolor" = $bgcolor,
"Version" = $version,
"Framerate" = $framerate,
"Framecount" = $framecount,
' Width ' = $rec [1],
' Height ' = $rec [3]
);
}
}
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/938855.html www.bkjia.com true http://www.bkjia.com/PHPjc/938855.html techarticle PHP read the Flash file high-wide frame number background color method, this article describes the PHP read Flash file high-wide frame number background color method. Share to everyone for your reference. Concrete implementation of the party ...