How to read the height, width, frame number and background color of a flash file in php,
The example in this article describes how PHP reads the height, width, frame number and background color of a flash file. Share it with everyone for your reference.
The specific implementation method is as follows:
Copy code The code is as follows:
/*
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 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 "The target file does not exist!";
return array( "error" => $filename ) ;
}
//Open file
$rs = fopen($filename,"r");
//Read file data
$str = fread( $rs , filesize( $filename ) ) ;
///
If($str[0] == "f")
{
//echo "
The file is already decompressed: ";
} else {
$first = substr($str,0,8);
$last = substr($str,8);
//
$last = gzuncompress($last);
//
$str = $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]));
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 )
{
//Convert to binary
$fbin = $this->mydecbin( $str , 8 ) ;
//Calculate the unit length of rec
$slen = bindec( substr( $fbin , 0 , 5 ) );
//Calculate the byte where 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 + 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]
);
}
}
?>
希望本文所述对大家的php程序设计有所帮助。
http://www.bkjia.com/PHPjc/938855.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/938855.htmlTechArticlephp读取flash文件高宽帧数背景颜色的方法, 本文实例讲述了php读取flash文件高宽帧数背景颜色的方法。分享给大家供大家参考。 具体实现方...