Esempio n. 1
0
function GetMIMEtype($filename)
{
    // include getID3() library (can be in a different directory if full path is specified)
    require_once '../getid3/getid3.php';
    // Initialize getID3 engine
    $getID3 = new getID3();
    $DeterminedMIMEtype = '';
    if ($fp = fopen($filename, 'rb')) {
        $ThisFileInfo = array('avdataoffset' => 0, 'avdataend' => 0);
        getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.tag.id3v2.php', __FILE__, true);
        $tag = new getid3_id3v2($fp, $ThisFileInfo);
        fseek($fp, $ThisFileInfo['avdataoffset'], SEEK_SET);
        $formattest = fread($fp, 16);
        // 16 bytes is sufficient for any format except ISO CD-image
        fclose($fp);
        $DeterminedFormatInfo = $getID3->GetFileFormat($formattest);
        $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type'];
    }
    return $DeterminedMIMEtype;
}
Esempio n. 2
0
function GetMIMEtype($filename)
{
    $filename = realpath($filename);
    if (!file_exists($filename)) {
        echo 'File does not exist: "' . htmlentities($filename) . '"<br>';
        return '';
    } elseif (!is_readable($filename)) {
        echo 'File is not readable: "' . htmlentities($filename) . '"<br>';
        return '';
    }
    // include getID3() library (can be in a different directory if full path is specified)
    require_once '../getid3/getid3.php';
    // Initialize getID3 engine
    $getID3 = new getID3();
    $DeterminedMIMEtype = '';
    if ($fp = fopen($filename, 'rb')) {
        $getID3->openfile($filename);
        if (empty($getID3->info['error'])) {
            // ID3v2 is the only tag format that might be prepended in front of files, and it's non-trivial to skip, easier just to parse it and know where to skip to
            getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.tag.id3v2.php', __FILE__, true);
            $getid3_id3v2 = new getid3_id3v2($getID3);
            $getid3_id3v2->Analyze();
            fseek($fp, $getID3->info['avdataoffset'], SEEK_SET);
            $formattest = fread($fp, 16);
            // 16 bytes is sufficient for any format except ISO CD-image
            fclose($fp);
            $DeterminedFormatInfo = $getID3->GetFileFormat($formattest);
            $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type'];
        } else {
            echo 'Failed to getID3->openfile "' . htmlentities($filename) . '"<br>';
        }
    } else {
        echo 'Failed to fopen "' . htmlentities($filename) . '"<br>';
    }
    return $DeterminedMIMEtype;
}
 function read_gzip($fd, &$ThisFileInfo)
 {
     $start_length = 10;
     $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
     //+---+---+---+---+---+---+---+---+---+---+
     //|ID1|ID2|CM |FLG|     MTIME     |XFL|OS |
     //+---+---+---+---+---+---+---+---+---+---+
     @fseek($fd, 0);
     $buffer = @fread($fd, $ThisFileInfo['filesize']);
     $arr_members = explode("‹", $buffer);
     while (true) {
         $is_wrong_members = false;
         $num_members = intval(count($arr_members));
         for ($i = 0; $i < $num_members; $i++) {
             if (strlen($arr_members[$i]) == 0) {
                 continue;
             }
             $buf = "‹" . $arr_members[$i];
             $attr = unpack($unpack_header, substr($buf, 0, $start_length));
             if (!$this->get_os_type(ord($attr['os']))) {
                 // Merge member with previous if wrong OS type
                 $arr_members[$i - 1] .= $buf;
                 $arr_members[$i] = '';
                 $is_wrong_members = true;
                 continue;
             }
         }
         if (!$is_wrong_members) {
             break;
         }
     }
     $ThisFileInfo['gzip']['files'] = array();
     $fpointer = 0;
     $idx = 0;
     for ($i = 0; $i < $num_members; $i++) {
         if (strlen($arr_members[$i]) == 0) {
             continue;
         }
         $thisThisFileInfo =& $ThisFileInfo['gzip']['member_header'][++$idx];
         $buff = "‹" . $arr_members[$i];
         $attr = unpack($unpack_header, substr($buff, 0, $start_length));
         $thisThisFileInfo['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']);
         $thisThisFileInfo['raw']['id1'] = ord($attr['cmethod']);
         $thisThisFileInfo['raw']['id2'] = ord($attr['cmethod']);
         $thisThisFileInfo['raw']['cmethod'] = ord($attr['cmethod']);
         $thisThisFileInfo['raw']['os'] = ord($attr['os']);
         $thisThisFileInfo['raw']['xflags'] = ord($attr['xflags']);
         $thisThisFileInfo['raw']['flags'] = ord($attr['flags']);
         $thisThisFileInfo['flags']['crc16'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x2);
         $thisThisFileInfo['flags']['extra'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x4);
         $thisThisFileInfo['flags']['filename'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x8);
         $thisThisFileInfo['flags']['comment'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x10);
         $thisThisFileInfo['compression'] = $this->get_xflag_type($thisThisFileInfo['raw']['xflags']);
         $thisThisFileInfo['os'] = $this->get_os_type($thisThisFileInfo['raw']['os']);
         if (!$thisThisFileInfo['os']) {
             $ThisFileInfo['error'][] = 'Read error on gzip file';
             return false;
         }
         $fpointer = 10;
         $arr_xsubfield = array();
         // bit 2 - FLG.FEXTRA
         //+---+---+=================================+
         //| XLEN  |...XLEN bytes of "extra field"...|
         //+---+---+=================================+
         if ($thisThisFileInfo['flags']['extra']) {
             $w_xlen = substr($buff, $fpointer, 2);
             $xlen = getid3_lib::LittleEndian2Int($w_xlen);
             $fpointer += 2;
             $thisThisFileInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen);
             // Extra SubFields
             //+---+---+---+---+==================================+
             //|SI1|SI2|  LEN  |... LEN bytes of subfield data ...|
             //+---+---+---+---+==================================+
             $idx = 0;
             while (true) {
                 if ($idx >= $xlen) {
                     break;
                 }
                 $si1 = ord(substr($buff, $fpointer + $idx++, 1));
                 $si2 = ord(substr($buff, $fpointer + $idx++, 1));
                 if ($si1 == 0x41 && $si2 == 0x70) {
                     $w_xsublen = substr($buff, $fpointer + $idx, 2);
                     $xsublen = getid3_lib::LittleEndian2Int($w_xsublen);
                     $idx += 2;
                     $arr_xsubfield[] = substr($buff, $fpointer + $idx, $xsublen);
                     $idx += $xsublen;
                 } else {
                     break;
                 }
             }
             $fpointer += $xlen;
         }
         // bit 3 - FLG.FNAME
         //+=========================================+
         //|...original file name, zero-terminated...|
         //+=========================================+
         // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz
         $thisThisFileInfo['filename'] = preg_replace('{.gz$}i', '', $ThisFileInfo['filename']);
         if ($thisThisFileInfo['flags']['filename']) {
             while (true) {
                 if (ord($buff[$fpointer]) == 0) {
                     $fpointer++;
                     break;
                 }
                 $thisThisFileInfo['filename'] .= $buff[$fpointer];
                 $fpointer++;
             }
         }
         // bit 4 - FLG.FCOMMENT
         //+===================================+
         //|...file comment, zero-terminated...|
         //+===================================+
         if ($thisThisFileInfo['flags']['comment']) {
             while (true) {
                 if (ord($buff[$fpointer]) == 0) {
                     $fpointer++;
                     break;
                 }
                 $thisThisFileInfo['comment'] .= $buff[$fpointer];
                 $fpointer++;
             }
         }
         // bit 1 - FLG.FHCRC
         //+---+---+
         //| CRC16 |
         //+---+---+
         if ($thisThisFileInfo['flags']['crc16']) {
             $w_crc = substr($buff, $fpointer, 2);
             $thisThisFileInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc);
             $fpointer += 2;
         }
         // bit 0 - FLG.FTEXT
         //if ($thisThisFileInfo['raw']['flags'] & 0x01) {
         //	Ignored...
         //}
         // bits 5, 6, 7 - reserved
         $thisThisFileInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4));
         $thisThisFileInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4));
         $ThisFileInfo['gzip']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['gzip']['files'], getid3_lib::CreateDeepArray($thisThisFileInfo['filename'], '/', $thisThisFileInfo['filesize']));
         if ($this->option_gzip_parse_contents) {
             // Try to inflate GZip
             $csize = 0;
             $inflated = '';
             $chkcrc32 = '';
             if (function_exists('gzinflate')) {
                 $cdata = substr($buff, $fpointer);
                 $cdata = substr($cdata, 0, strlen($cdata) - 8);
                 $csize = strlen($cdata);
                 $inflated = gzinflate($cdata);
                 // Calculate CRC32 for inflated content
                 $thisThisFileInfo['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $thisThisFileInfo['crc32']);
                 // determine format
                 $formattest = substr($inflated, 0, 32774);
                 $newgetID3 = new getID3();
                 $determined_format = $newgetID3->GetFileFormat($formattest);
                 unset($newgetID3);
                 // file format is determined
                 switch (@$determined_format['module']) {
                     case 'tar':
                         // view TAR-file info
                         if (file_exists(GETID3_INCLUDEPATH . $determined_format['include']) && @(include_once GETID3_INCLUDEPATH . $determined_format['include'])) {
                             getid3_tar::read_tar($inflated, $ThisFileInfo['gzip']['member_header'][$idx]);
                         }
                         break;
                     case '':
                     default:
                         // unknown or unhandled format
                         break;
                 }
             }
         }
     }
     return true;
 }
Esempio n. 4
0
 /**
  *
  * @access public
  * @return
  **/
 public function getID3Mime()
 {
     $mime = NULL;
     $filename = realpath($this->file_src_pathname);
     if (!file_exists($filename)) {
         $this->error = 'File does not exist: "' . htmlentities($filename);
         return false;
     } elseif (!is_readable($filename)) {
         $this->error = 'File is not readable: "' . htmlentities($filename);
         return false;
     }
     require_once CAT_PATH . '/modules/lib_getid3/getid3/getid3.php';
     $getID3 = new getID3();
     if ($fp = fopen($filename, 'rb')) {
         $getID3->openfile($filename);
         if (empty($getID3->info['error'])) {
             // ID3v2 is the only tag format that might be prepended in front of files, and it's non-trivial to skip, easier just to parse it and know where to skip to
             getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.tag.id3v2.php', __FILE__, true);
             $getid3_id3v2 = new getid3_id3v2($getID3);
             $getid3_id3v2->Analyze();
             fseek($fp, $getID3->info['avdataoffset'], SEEK_SET);
             $formattest = fread($fp, 16);
             // 16 bytes is sufficient for any format except ISO CD-image
             fclose($fp);
             $DeterminedFormatInfo = $getID3->GetFileFormat($formattest);
             $mime = $DeterminedFormatInfo['mime_type'];
         } else {
             $this->error = 'Failed to getID3->openfile "' . htmlentities($filename);
         }
     } else {
         $this->error = 'Failed to fopen "' . htmlentities($filename);
     }
     $this->log()->logDebug('MIME type detected as [' . $mime . '] by getID3 library');
     return $mime;
 }
 public function mime_getid3($path)
 {
     $determined_mime_type = false;
     if (file_exists(MODPATH . 'getid3/getid3/getid3.php')) {
         // include getID3() library (can be in a different directory if full path is specified)
         require_once MODPATH . 'getid3/getid3/getid3.php';
         // Initialize getID3 engine
         $get_id3 = new getID3();
         if ($fp = fopen($path, 'rb')) {
             $this_file_info = array('avdataoffset' => 0, 'avdataend' => 0);
             getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.tag.id3v2.php', __FILE__, true);
             $tag = new getid3_id3v2($fp, $this_file_info);
             fseek($fp, $this_file_info['avdataoffset'], SEEK_SET);
             $formattest = fread($fp, 16);
             // 16 bytes is sufficient for any format except ISO CD-image
             fclose($fp);
             $determined_format_info = $get_id3->GetFileFormat($formattest);
             $determined_mime_type = ($mime = $determined_format_info['mime_type']) ? $mime : FALSE;
         }
     }
     return $determined_mime_type;
 }
Esempio n. 6
-1
 /**
  * Get file mime type
  * 
  * @param string $filename The file name 
  * 
  * @return string The MIME type
  */
 public function getMime($filename)
 {
     require_once SRPATH_LIBRARY . '/media/getid3/getid3.php';
     // Initialize getID3 engine
     $getID3 = new getID3();
     $determinedMimeType = '';
     if ($fp = fopen($filename, 'rb')) {
         $thisFileInfo = array('avdataoffset' => 0, 'avdataend' => 0);
         getid3_lib::IncludeDependency(SRPATH_LIBRARY . '/media/getid3/module.tag.id3v2.php', __FILE__, true);
         $tag = new getid3_id3v2($fp, $thisFileInfo);
         fseek($fp, $thisFileInfo['avdataoffset'], SEEK_SET);
         $formattest = fread($fp, 16);
         // 16 bytes is sufficient for any format except ISO CD-image
         fclose($fp);
         $determinedFormatInfo = $getID3->GetFileFormat($formattest);
         $determinedMimeType = $determinedFormatInfo['mime_type'];
     }
     return $determinedMimeType;
 }