Php: reading flash files, high-width frames, background color code _ PHP Tutorial

Source: Internet
Author: User
Php reads the background color code of the high-width frames of flash files. In the php Tutorial, how does one read the background color code of the high-width frames of flash files? Php * Example: export filedataad_files55.swf; $ flashnewflash (); $ flash-getswfinfo ($ file); echo file width

The php Tutorial reads the background color code for the high-width frames of flash files.

/*
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 the background color is returned
Public $ need_back_color = false;

// Whether to return the 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 the file
$ Rs = fopen ($ filename, "r ");

// Read the 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"
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)
{
// Convert to binary
$ Fbin = $ this-> mydecbin ($ str, 8 );

// Calculates the unit length of rec.
$ Slen = bindec (substr ($ fbin, 0, 5 ));

// Calculate the bytes 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 + 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
$ 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 + 11]) * 256 + ord ($ str [$ recsize + 10]);
}

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

?>


Why? Php/* example: $ file = '/data/ad_files/5/5.swf'; $ flash = new flash (); $ flash = $ flash-getswfinfo ($ file ); echo file width...

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.