getID3::GetFileFormat() –

You appear to be a bot. Output may be restricted



$mixed|false = getID3::GetFileFormat( $filedata, $filename );


( string ) required
( string ) optional




File name: wordpress/wp-includes/ID3/getid3.php

1 to 36 of 36
  public function GetFileFormat(&$filedata, $filename='') {
    // this function will determine the format of a file based on usually
    // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,
    // and in the case of ISO CD image, 6 bytes offset 32kb from the start
    // of the file).

    // Identify file format - loop through $format_info and detect with reg expr
    foreach ($this->getID3::GetFileFormatArray() as $format_name => $info) {
      // The /s switch on preg_match() forces preg_match() NOT to treat
      // newline (0x0A) characters as special chars but do a binary match
      if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {
        $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
        return $info;

    if (preg_match('#\\.mp[123a]$#i', $filename)) {
      // Too many mp3 encoders on the market put garbage in front of mpeg files
      // use assume format on these if format detection failed
      $GetFileFormatArray = $this->getID3::GetFileFormatArray();
      $info = $GetFileFormatArray['mp3'];
      $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
      return $info;
    } elseif (preg_match('#\\.cue$#i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
      // there's not really a useful consistent "magic" at the beginning of .cue files to identify them
      // so until I think of something better, just go by filename if all other format checks fail
      // and verify there's at least one instance of "TRACK xx AUDIO" in the file
      $GetFileFormatArray = $this->getID3::GetFileFormatArray();
      $info = $GetFileFormatArray['cue'];
      $info['include']   = 'module.'.$info['group'].'.'.$info['module'].'.php';
      return $info;

    return false;

 View on GitHub View on Trac