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