]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - vendor/james-heinrich/getid3/demos/demo.mimeonly.php
MediaWiki 1.30.2-scripts
[autoinstalls/mediawiki.git] / vendor / james-heinrich / getid3 / demos / demo.mimeonly.php
1 <?php
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 /////////////////////////////////////////////////////////////////
8 //                                                             //
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                             //
13 //                                                            ///
14 /////////////////////////////////////////////////////////////////
15
16 die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']);
17
18
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>';
21
22 if (!empty($_REQUEST['filename'])) {
23
24         echo 'The file "'.htmlentities($_REQUEST['filename']).'" has a MIME type of "'.htmlentities(GetMIMEtype($_REQUEST['filename'])).'"';
25
26 } else {
27
28         echo 'Usage: <span style="font-family: monospace;">'.htmlentities($_SERVER['PHP_SELF']).'?filename=<i>filename.ext</i></span>';
29
30 }
31
32
33 function GetMIMEtype($filename) {
34         $filename = realpath($filename);
35         if (!file_exists($filename)) {
36                 echo 'File does not exist: "'.htmlentities($filename).'"<br>';
37                 return '';
38         } elseif (!is_readable($filename)) {
39                 echo 'File is not readable: "'.htmlentities($filename).'"<br>';
40                 return '';
41         }
42
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
46         $getID3 = new getID3;
47
48         $DeterminedMIMEtype = '';
49         if ($fp = fopen($filename, 'rb')) {
50                 $getID3->openfile($filename);
51                 if (empty($getID3->info['error'])) {
52
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();
57
58                         fseek($fp, $getID3->info['avdataoffset'], SEEK_SET);
59                         $formattest = fread($fp, 16);  // 16 bytes is sufficient for any format except ISO CD-image
60                         fclose($fp);
61
62                         $DeterminedFormatInfo = $getID3->GetFileFormat($formattest);
63                         $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type'];
64
65                 } else {
66                         echo 'Failed to getID3->openfile "'.htmlentities($filename).'"<br>';
67                 }
68         } else {
69                 echo 'Failed to fopen "'.htmlentities($filename).'"<br>';
70         }
71         return $DeterminedMIMEtype;
72 }
73
74 echo '</body></html>';