2 /////////////////////////////////////////////////////////////////
3 /// getID3() by James Heinrich <info@getid3.org> //
4 // available at http://getid3.sourceforge.net //
5 // or http://www.getid3.org //
6 // also https://github.com/JamesHeinrich/getID3 //
7 /////////////////////////////////////////////////////////////////
9 // /demo/demo.mimeonly.php - part of getID3() //
10 // Sample script for scanning a single file and returning only //
11 // the MIME information //
12 // See readme.txt for more details //
14 /////////////////////////////////////////////////////////////////
16 die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']);
19 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
20 echo '<html><head><title>getID3 demos - MIME type only</title><style type="text/css">BODY, TD, TH { font-family: sans-serif; font-size: 10pt; }</style></head><body>';
22 if (!empty($_REQUEST['filename'])) {
24 echo 'The file "'.htmlentities($_REQUEST['filename']).'" has a MIME type of "'.htmlentities(GetMIMEtype($_REQUEST['filename'])).'"';
28 echo 'Usage: <span style="font-family: monospace;">'.htmlentities($_SERVER['PHP_SELF']).'?filename=<i>filename.ext</i></span>';
33 function GetMIMEtype($filename) {
34 $filename = realpath($filename);
35 if (!file_exists($filename)) {
36 echo 'File does not exist: "'.htmlentities($filename).'"<br>';
38 } elseif (!is_readable($filename)) {
39 echo 'File is not readable: "'.htmlentities($filename).'"<br>';
43 // include getID3() library (can be in a different directory if full path is specified)
44 require_once('../getid3/getid3.php');
45 // Initialize getID3 engine
48 $DeterminedMIMEtype = '';
49 if ($fp = fopen($filename, 'rb')) {
50 $getID3->openfile($filename);
51 if (empty($getID3->info['error'])) {
53 // 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
54 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
55 $getid3_id3v2 = new getid3_id3v2($getID3);
56 $getid3_id3v2->Analyze();
58 fseek($fp, $getID3->info['avdataoffset'], SEEK_SET);
59 $formattest = fread($fp, 16); // 16 bytes is sufficient for any format except ISO CD-image
62 $DeterminedFormatInfo = $getID3->GetFileFormat($formattest);
63 $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type'];
66 echo 'Failed to getID3->openfile "'.htmlentities($filename).'"<br>';
69 echo 'Failed to fopen "'.htmlentities($filename).'"<br>';
71 return $DeterminedMIMEtype;
74 echo '</body></html>';