Beispiel #1
0
 /**
  *
  * @param type $filedata
  * @param type $filename
  * @return string|boolean
  */
 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
     $GetFileFormatArray = $this->GetFileFormatArray();
     foreach ($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['class'] = 'GetId3_Module_' . GetId3_Lib_Helper::toCamelCase($info['group'], '-', true) . '_' . ucfirst($info['module']);
             $info['include'] = str_replace('_', DIRECTORY_SEPARATOR, $info['class']) . '.php';
             return $info;
         }
     }
     if (preg_match('#\\.mp[123a]$#i', $filename)) {
         // Too many mp3 encoders on the market put gabage in front of mpeg files
         // use assume format on these if format detection failed
         $info = $GetFileFormatArray['mp3'];
         $info['class'] = 'GetId3_Module_' . GetId3_Lib_Helper::toCamelCase($info['group'], '-', true) . '_' . ucfirst($info['module']);
         $info['include'] = str_replace('_', DIRECTORY_SEPARATOR, $info['class']) . '.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
         $info = $GetFileFormatArray['cue'];
         $info['class'] = 'GetId3_Module_' . GetId3_Lib_Helper::toCamelCase($info['group'], '-', true) . '_' . ucfirst($info['module']);
         $info['include'] = str_replace('_', DIRECTORY_SEPARATOR, $info['class']) . '.php';
         return $info;
     }
     return false;
 }