1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
<?php
use JamesHeinrich\GetID3;
require __DIR__ . "/../vendor/autoload.php";
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
// available at https://github.com/JamesHeinrich/getID3 //
// or https://www.getid3.org //
// or http://getid3.sourceforge.net //
// //
// /demo/demo.mimeonly.php - part of getID3() //
// Sample script for scanning a single file and returning only //
// the MIME information //
// see readme.txt for more details //
// ///
/////////////////////////////////////////////////////////////////
die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
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>';
if (!empty($_REQUEST['filename'])) {
echo 'The file "'.htmlentities($_REQUEST['filename']).'" has a MIME type of "'.htmlentities(GetMIMEtype($_REQUEST['filename'])).'"';
} else {
echo 'Usage: <span style="font-family: monospace;">'.htmlentities($_SERVER['PHP_SELF']).'?filename=<i>filename.ext</i></span>';
}
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 '';
}
// Initialize getID3 engine
$getID3 = new GetID3\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_id3v2 = new GetID3\Module\Tag\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;
}
echo '</body></html>';
|