Home >Backend Development >PHP Tutorial >PHP reads flash file height, width, frame number, background color code_PHP tutorial
php tutorial to read flash file height, width, frame number, background color code
/*
Example:
$file = '/data/ad_files /5/5.swf';
$flash = new flash();
$flash = $flash->getswfinfo($file);
echo "
The width and height of the file are: ".$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 Return version
public $need_version = false ;
//Whether to return frame rate
public $need_framerate = false ;
//Whether to return frame number
public $need_framecount = false ;public function __construct()
{}
public function getswfinfo( $filename )
$str = fread( $rs, filesize( $filename ) ) ;
{
if ( file_exists($ filename) ) {
//echo "File modification time:".date("m d y h:i:s.", filemtime($filename))."
";
} else {
//echo "The target file does not exist!"; $filename,"r");
//Read file data///
while(strlen($fbin)<8)$fbin="0".$fbin;
if( $str[0] == "f")
{
//echo "
The file is already a decompressed file:";
} else {
$first = substr($ str,0,8);
$last = substr($str,8); first . $last ;
$str[0] = "f";
//echo "
Decompressed file information:";
}
$info = $this->getinfo( $str );
fclose ( $rs ) ;
return $info;
}
private function mydecbin($str,$index)
{
$fbin = decbin(ord($str[$index]));return $fbin ;
{
}
private function colorhex($data)$tmp = dechex($data);
if ( strlen($tmp)<2 ) {
$tmp='0' . $tmp ;
}
return $tmp; Into binary
$fbin = $this->mydecbin( $str, 8) ;//Calculate the unit length of rec
$recbin = $fbin ;
$slen = bindec( substr( $fbin, 0, 5 ) );
//Calculate the byte where rec is located
$recsize = $slen * 4 + 5;
$recsize = ceil( $recsize / 8);
//rec binaryfor( $i = 9 ; $i < $recsize + 8 ; $i++ )
{
$recbin .= $this- >mydecbin( $str ,$i );
}//rec数据
$rec = array();
for( $i = 0 ; $i < 4 ; $i++ )
{
$rec[] = bindec( substr( $recbin , 5 + $i * $slen , $slen ) ) / 20 ;
}
if ( $this->need_back_color ) {
//背景颜色
for( $i = $recsize + 12 ; $i < strlen ( $str ) ; $i ++ )
{
if ( ord( $str[$i] ) == 67 && 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 = ord( $str[3] );
}
if ( $this->need_framerate ) {
//帧速率
$framerate = ord( $str[$recsize + 8] ) / 256 + ord( $str[$recsize + 9] ) ;
}if ( $this->need_framecount ) {
//帧数量
$framecount = ord( $str[$recsize + 11] ) * 256 + ord( $str[$recsize + 10] );
}
return array ( "bgcolor" => $bgcolor ,
"version" => $version ,
"framerate" => $framerate ,
"framecount" => $framecount ,
'width'=>$rec[1],
'height'=>$rec[3]
);
}
}?>