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.browse.php - part of getID3() // 9// Sample script for browsing/scanning files and displaying // 10// information returned by getID3() // 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 17define('GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK', false); // if enabled, shows "edit" links (to /demos/demo.write.php) to allow ID3/APE/etc tag editing on applicable file types 18define('GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK', false); // if enabled, shows "delete" links to delete files from the browse interface 19define('GETID3_DEMO_BROWSE_ALLOW_MD5_LINK', false); // if enabled, shows "enable" link for MD5 hashes for file/data/source 20 21///////////////////////////////////////////////////////////////// 22// die if magic_quotes_runtime or magic_quotes_gpc are set 23if (version_compare(PHP_VERSION, '7.4.0', '<')) { // get_magic_quotes_runtime / get_magic_quotes_gpc functions give deprecation warnings in PHP v7.4 24 if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) { 25 die('magic_quotes_runtime is enabled, getID3 will not run.'); 26 } 27 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { 28 die('magic_quotes_gpc is enabled, getID3 will not run.'); 29 } 30} 31///////////////////////////////////////////////////////////////// 32 33require_once('../getid3/getid3.php'); 34 35$PageEncoding = 'UTF-8'; 36$FileSystemEncoding = ((GETID3_OS_ISWINDOWS && version_compare(PHP_VERSION, '7.1.0', '<')) ? 'Windows-1252' : 'UTF-8'); 37$writescriptfilename = 'demo.write.php'; 38 39// Needed for windows only. Leave commented-out to auto-detect, only define here if auto-detection does not work properly 40//define('GETID3_HELPERAPPSDIR', 'C:\\helperapps\\'); 41 42// Initialize getID3 engine 43$getID3 = new getID3; 44$getID3->setOption(array('encoding' => $PageEncoding)); 45 46$getID3checkColor_Head = 'CCCCDD'; 47$getID3checkColor_DirectoryLight = 'FFCCCC'; 48$getID3checkColor_DirectoryDark = 'EEBBBB'; 49$getID3checkColor_FileLight = 'EEEEEE'; 50$getID3checkColor_FileDark = 'DDDDDD'; 51$getID3checkColor_UnknownLight = 'CCCCFF'; 52$getID3checkColor_UnknownDark = 'BBBBDD'; 53 54 55/////////////////////////////////////////////////////////////////////////////// 56 57 58header('Content-Type: text/html; charset='.$PageEncoding); 59echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'; 60echo '<html><head>'; 61echo '<title>getID3() - /demo/demo.browse.php (sample script)</title>'; 62echo '<link rel="stylesheet" href="getid3.css" type="text/css">'; 63echo '<meta http-equiv="Content-Type" content="text/html;charset='.$PageEncoding.'" />'; 64echo '</head><body>'; 65 66if (isset($_REQUEST['deletefile']) && GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { 67 if (file_exists($_REQUEST['deletefile'])) { 68 if (unlink($_REQUEST['deletefile'])) { 69 $deletefilemessage = 'Successfully deleted '.$_REQUEST['deletefile']; 70 } else { 71 $deletefilemessage = 'FAILED to delete '.$_REQUEST['deletefile'].' - error deleting file'; 72 } 73 } else { 74 $deletefilemessage = 'FAILED to delete '.$_REQUEST['deletefile'].' - file does not exist'; 75 } 76 if (isset($_REQUEST['noalert'])) { 77 echo '<span style="font-weight: bold; color: #'.(($deletefilemessage[0] == 'F') ? 'FF0000' : '008000').';">'.htmlentities($deletefilemessage, ENT_QUOTES).'</span><hr>'; 78 } else { 79 echo '<script type="text/javascript">alert("'.addslashes($deletefilemessage).'");</script>'; 80 } 81} 82 83 84if (isset($_REQUEST['filename'])) { 85 86 if (!file_exists($_REQUEST['filename']) || !is_file($_REQUEST['filename'])) { 87 die(getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $_REQUEST['filename'].' does not exist')); 88 } 89 $starttime = microtime(true); 90 91 //$getID3->setOption(array( 92 // 'option_md5_data' => $AutoGetHashes, 93 // 'option_sha1_data' => $AutoGetHashes, 94 //)); 95 $ThisFileInfo = $getID3->analyze($_REQUEST['filename']); 96 $AutoGetHashes = (bool) (isset($ThisFileInfo['filesize']) && ($ThisFileInfo['filesize'] > 0) && ($ThisFileInfo['filesize'] < (50 * 1048576))); // auto-get md5_data, md5_file, sha1_data, sha1_file if filesize < 50MB, and NOT zero (which may indicate a file>2GB) 97 $AutoGetHashes = ($AutoGetHashes && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK); 98 if ($AutoGetHashes) { 99 $ThisFileInfo['md5_file'] = md5_file($_REQUEST['filename']); 100 $ThisFileInfo['sha1_file'] = sha1_file($_REQUEST['filename']); 101 } 102 103 104 $getID3->CopyTagsToComments($ThisFileInfo); 105 106 $listdirectory = dirname($_REQUEST['filename']); 107 $listdirectory = realpath($listdirectory); // get rid of /../../ references 108 109 if (GETID3_OS_ISWINDOWS) { 110 // this mostly just gives a consistant look to Windows and *nix filesystems 111 // (windows uses \ as directory seperator, *nix uses /) 112 $listdirectory = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory.'/'); 113 } 114 115 if (preg_match('#^(ht|f)tp://#', $_REQUEST['filename'])) { 116 echo '<i>Cannot browse remote filesystems</i><br>'; 117 } else { 118 echo 'Browse: <a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">'.getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $listdirectory).'</a><br>'; 119 } 120 121 getid3_lib::ksort_recursive($ThisFileInfo); 122 echo table_var_dump($ThisFileInfo, false, $PageEncoding); 123 $endtime = microtime(true); 124 echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.<br>'; 125 126} else { 127 128 $listdirectory = (isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'); 129 $listdirectory = getid3_lib::truepath($listdirectory); // get rid of /../../ references 130 $currentfulldir = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory).'/'; // this mostly just gives a consistant look to Windows and *nix filesystems: (Windows uses \ as directory seperator, *nix uses /) 131 132 ob_start(); 133 if ($handle = opendir($listdirectory)) { 134 135 ob_end_clean(); 136 echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces 137 echo 'Processing'; 138 139 $starttime = microtime(true); 140 141 $TotalScannedUnknownFiles = 0; 142 $TotalScannedKnownFiles = 0; 143 $TotalScannedPlaytimeFiles = 0; 144 $TotalScannedBitrateFiles = 0; 145 $TotalScannedFilesize = 0; 146 $TotalScannedPlaytime = 0; 147 $TotalScannedBitrate = 0; 148 $FilesWithWarnings = 0; 149 $FilesWithErrors = 0; 150 151 while ($file = readdir($handle)) { 152 $currentfilename = $listdirectory.'/'.$file; 153 set_time_limit(30); // allocate another 30 seconds to process this file - should go much quicker than this unless intense processing (like bitrate histogram analysis) is enabled 154 echo ' <span title="'.htmlentities($file, ENT_QUOTES).'">.</span>'; // progress indicator dot 155 flush(); // make sure the dot is shown, otherwise it's useless 156 switch ($file) { 157 case '..': 158 $ParentDir = realpath($file.'/..').'/'; 159 if (GETID3_OS_ISWINDOWS) { 160 $ParentDir = str_replace(DIRECTORY_SEPARATOR, '/', $ParentDir); 161 } 162 $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $ParentDir; 163 continue 2; 164 break; 165 166 case '.': 167 // ignore 168 continue 2; 169 break; 170 } 171 // symbolic-link-resolution enhancements by davidbullock״ech-center*com 172 $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link 173 $TargetObjectType = filetype($TargetObject); // Check file type without examining extension 174 175 if ($TargetObjectType == 'dir') { 176 177 $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $file; 178 179 } elseif ($TargetObjectType == 'file') { 180 181 $getID3->setOption(array('option_md5_data' => (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK))); 182 $fileinformation = $getID3->analyze($currentfilename); 183 184 $getID3->CopyTagsToComments($fileinformation); 185 186 $TotalScannedFilesize += (isset($fileinformation['filesize']) ? $fileinformation['filesize'] : 0); 187 188 if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { 189 $fileinformation['md5_file'] = md5_file($currentfilename); 190 } 191 192 if (!empty($fileinformation['fileformat'])) { 193 $DirectoryContents[$currentfulldir]['known'][$file] = $fileinformation; 194 $TotalScannedPlaytime += (isset($fileinformation['playtime_seconds']) ? $fileinformation['playtime_seconds'] : 0); 195 $TotalScannedBitrate += (isset($fileinformation['bitrate']) ? $fileinformation['bitrate'] : 0); 196 $TotalScannedKnownFiles++; 197 } else { 198 $DirectoryContents[$currentfulldir]['other'][$file] = $fileinformation; 199 $DirectoryContents[$currentfulldir]['other'][$file]['playtime_string'] = '-'; 200 $TotalScannedUnknownFiles++; 201 } 202 if (isset($fileinformation['playtime_seconds']) && ($fileinformation['playtime_seconds'] > 0)) { 203 $TotalScannedPlaytimeFiles++; 204 } 205 if (isset($fileinformation['bitrate']) && ($fileinformation['bitrate'] > 0)) { 206 $TotalScannedBitrateFiles++; 207 } 208 209 } else { 210 211 echo '<div style="color: red;">Unknown filesystem entry: "'.htmlentities($currentfilename, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'"</div>'; 212 213 } 214 } 215 $endtime = microtime(true); 216 closedir($handle); 217 echo 'done<br>'; 218 echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.<br>'; 219 flush(); 220 221 $columnsintable = 14; 222 echo '<table class="table" cellspacing="0" cellpadding="3">'; 223 224 echo '<tr bgcolor="#'.$getID3checkColor_Head.'"><th colspan="'.$columnsintable.'">Files in '.getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $currentfulldir).'</th></tr>'; 225 $rowcounter = 0; 226 foreach ($DirectoryContents as $dirname => $val) { 227 if (isset($DirectoryContents[$dirname]['dir']) && is_array($DirectoryContents[$dirname]['dir'])) { 228 uksort($DirectoryContents[$dirname]['dir'], 'MoreNaturalSort'); 229 foreach ($DirectoryContents[$dirname]['dir'] as $filename => $fileinfo) { 230 echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_DirectoryLight : $getID3checkColor_DirectoryDark).'">'; 231 if ($filename == '..') { 232 echo '<td colspan="'.$columnsintable.'">'; 233 echo '<form action="'.htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" method="get">'; 234 echo 'Parent directory: '; 235 echo '<input type="text" name="listdirectory" size="50" style="background-color: '.$getID3checkColor_DirectoryDark.';" value="'; 236 if (GETID3_OS_ISWINDOWS) { 237 echo htmlentities(str_replace(DIRECTORY_SEPARATOR, '/', realpath($dirname.$filename)), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding); 238 } else { 239 echo htmlentities(realpath($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding); 240 } 241 echo '"> <input type="submit" value="Go">'; 242 echo '</form></td>'; 243 } else { 244 $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $FileSystemEncoding); // do filesystems always return filenames in ISO-8859-1? 245 $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); 246 echo '<td colspan="'.$columnsintable.'"><a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'"><b>'.$escaped_filename.'</b></a></td>'; 247 } 248 echo '</tr>'; 249 } 250 } 251 252 echo '<tr bgcolor="#'.$getID3checkColor_Head.'">'; 253 echo '<th>Filename</th>'; 254 echo '<th>File Size</th>'; 255 echo '<th>Format</th>'; 256 echo '<th>Playtime</th>'; 257 echo '<th>Bitrate</th>'; 258 echo '<th>Artist</th>'; 259 echo '<th>Title</th>'; 260 if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { 261 echo '<th>MD5 File (File) (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">disable</a>)</th>'; 262 echo '<th>MD5 Data (File) (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">disable</a>)</th>'; 263 echo '<th>MD5 Data (Source) (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">disable</a>)</th>'; 264 } else { 265 echo '<th colspan="3">MD5 Data'.(GETID3_DEMO_BROWSE_ALLOW_MD5_LINK ?' (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'&ShowMD5=1', ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">enable</a>)' : '').'</th>'; 266 } 267 echo '<th>Tags</th>'; 268 echo '<th>Errors & Warnings</th>'; 269 echo (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK ? '<th>Edit</th>' : ''); 270 echo (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK ? '<th>Delete</th>' : ''); 271 echo '</tr>'; 272 273 if (isset($DirectoryContents[$dirname]['known']) && is_array($DirectoryContents[$dirname]['known'])) { 274 uksort($DirectoryContents[$dirname]['known'], 'MoreNaturalSort'); 275 foreach ($DirectoryContents[$dirname]['known'] as $filename => $fileinfo) { 276 echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_FileDark : $getID3checkColor_FileLight).'">'; 277 $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $FileSystemEncoding); // do filesystems always return filenames in ISO-8859-1? 278 $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); 279 echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" title="View detailed analysis">'.$escaped_filename.'</a></td>'; 280 echo '<td align="right"> '.number_format($fileinfo['filesize']).'</td>'; 281 echo '<td align="right"> '.NiceDisplayFiletypeFormat($fileinfo).'</td>'; 282 echo '<td align="right"> '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').'</td>'; 283 echo '<td align="right"> '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000, 0, ((isset($fileinfo['audio']['bitrate_mode']) && ($fileinfo['audio']['bitrate_mode'] == 'vbr')) ? true : false)) : '-').'</td>'; 284 echo '<td align="left"> '.(isset($fileinfo['comments_html']['artist']) ? implode('<br>', $fileinfo['comments_html']['artist']) : ((isset($fileinfo['video']['resolution_x']) && isset($fileinfo['video']['resolution_y'])) ? $fileinfo['video']['resolution_x'].'x'.$fileinfo['video']['resolution_y'] : '')).'</td>'; 285 echo '<td align="left"> '.(isset($fileinfo['comments_html']['title']) ? implode('<br>', $fileinfo['comments_html']['title']) : (isset($fileinfo['video']['frame_rate']) ? number_format($fileinfo['video']['frame_rate'], 3).'fps' : '')).'</td>'; 286 if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { 287 echo '<td align="left"><tt>'.(isset($fileinfo['md5_file']) ? $fileinfo['md5_file'] : ' ').'</tt></td>'; 288 echo '<td align="left"><tt>'.(isset($fileinfo['md5_data']) ? $fileinfo['md5_data'] : ' ').'</tt></td>'; 289 echo '<td align="left"><tt>'.(isset($fileinfo['md5_data_source']) ? $fileinfo['md5_data_source'] : ' ').'</tt></td>'; 290 } else { 291 echo '<td align="center" colspan="3">-</td>'; 292 } 293 echo '<td align="left"> '.(!empty($fileinfo['tags']) ? implode(', ', array_keys($fileinfo['tags'])) : '').'</td>'; 294 295 echo '<td align="left"> '; 296 if (!empty($fileinfo['warning'])) { 297 $FilesWithWarnings++; 298 echo '<a href="#" onClick="alert(\''.htmlentities(str_replace("'", "\\'", preg_replace('#[\r\n\t]+#', ' ', implode('\\n', $fileinfo['warning']))), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("; \n", $fileinfo['warning']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">warning</a><br>'; 299 } 300 if (!empty($fileinfo['error'])) { 301 $FilesWithErrors++; 302 echo '<a href="#" onClick="alert(\''.htmlentities(str_replace("'", "\\'", preg_replace('#[\r\n\t]+#', ' ', implode('\\n', $fileinfo['error']))), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("; \n", $fileinfo['error']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">error</a><br>'; 303 } 304 echo '</td>'; 305 306 if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { 307 echo '<td align="left"> '; 308 $fileinfo['fileformat'] = (isset($fileinfo['fileformat']) ? $fileinfo['fileformat'] : ''); 309 switch ($fileinfo['fileformat']) { 310 case 'mp3': 311 case 'mp2': 312 case 'mp1': 313 case 'flac': 314 case 'mpc': 315 case 'real': 316 echo '<a href="'.htmlentities($writescriptfilename.'?Filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" title="Edit tags">edit tags</a>'; 317 break; 318 case 'ogg': 319 if (isset($fileinfo['audio']['dataformat']) && ($fileinfo['audio']['dataformat'] == 'vorbis')) { 320 echo '<a href="'.htmlentities($writescriptfilename.'?Filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" title="Edit tags">edit tags</a>'; 321 } 322 break; 323 default: 324 break; 325 } 326 echo '</td>'; 327 } 328 if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { 329 echo '<td align="left"> <a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes(htmlentities($dirname.$filename)).'? \n(this action cannot be un-done)\');" title="'.htmlentities('Permanently delete '."\n".$filename."\n".' from'."\n".' '.$dirname, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">delete</a></td>'; 330 } 331 echo '</tr>'; 332 } 333 } 334 335 if (isset($DirectoryContents[$dirname]['other']) && is_array($DirectoryContents[$dirname]['other'])) { 336 uksort($DirectoryContents[$dirname]['other'], 'MoreNaturalSort'); 337 foreach ($DirectoryContents[$dirname]['other'] as $filename => $fileinfo) { 338 echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_UnknownDark : $getID3checkColor_UnknownLight).'">'; 339 $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); 340 $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); 341 echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'"><i>'.$escaped_filename.'</i></a></td>'; 342 echo '<td align="right"> '.(isset($fileinfo['filesize']) ? number_format($fileinfo['filesize']) : '-').'</td>'; 343 echo '<td align="right"> '.NiceDisplayFiletypeFormat($fileinfo).'</td>'; 344 echo '<td align="right"> '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').'</td>'; 345 echo '<td align="right"> '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000) : '-').'</td>'; 346 echo '<td align="left"> </td>'; // Artist 347 echo '<td align="left"> </td>'; // Title 348 echo '<td align="left" colspan="3"> </td>'; // MD5_data 349 echo '<td align="left"> </td>'; // Tags 350 351 //echo '<td align="left"> </td>'; // Warning/Error 352 echo '<td align="left"> '; 353 if (!empty($fileinfo['warning'])) { 354 $FilesWithWarnings++; 355 echo '<a href="#" onClick="alert(\''.htmlentities(implode('\\n', $fileinfo['warning']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("\n", $fileinfo['warning']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">warning</a><br>'; 356 } 357 if (!empty($fileinfo['error'])) { 358 if ($fileinfo['error'][0] != 'unable to determine file format') { 359 $FilesWithErrors++; 360 echo '<a href="#" onClick="alert(\''.htmlentities(implode('\\n', $fileinfo['error']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("\n", $fileinfo['error']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">error</a><br>'; 361 } 362 } 363 echo '</td>'; 364 365 if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { 366 echo '<td align="left"> </td>'; // Edit 367 } 368 if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { 369 echo '<td align="left"> <a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes($dirname.$filename).'? \n(this action cannot be un-done)\');" title="Permanently delete '.addslashes($dirname.$filename).'">delete</a></td>'; 370 } 371 echo '</tr>'; 372 } 373 } 374 375 echo '<tr bgcolor="#'.$getID3checkColor_Head.'">'; 376 echo '<td><b>Average:</b></td>'; 377 echo '<td align="right">'.number_format($TotalScannedFilesize / max($TotalScannedKnownFiles, 1)).'</td>'; 378 echo '<td> </td>'; 379 echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime / max($TotalScannedPlaytimeFiles, 1)).'</td>'; 380 echo '<td align="right">'.BitrateText(round(($TotalScannedBitrate / 1000) / max($TotalScannedBitrateFiles, 1))).'</td>'; 381 echo '<td rowspan="2" colspan="'.($columnsintable - 5).'"><table class="table" border="0" cellspacing="0" cellpadding="2"><tr><th align="right">Identified Files:</th><td align="right">'.number_format($TotalScannedKnownFiles).'</td><td> </td><th align="right">Errors:</th><td align="right">'.number_format($FilesWithErrors).'</td></tr><tr><th align="right">Unknown Files:</th><td align="right">'.number_format($TotalScannedUnknownFiles).'</td><td> </td><th align="right">Warnings:</th><td align="right">'.number_format($FilesWithWarnings).'</td></tr></table>'; 382 echo '</tr>'; 383 echo '<tr bgcolor="#'.$getID3checkColor_Head.'">'; 384 echo '<td><b>Total:</b></td>'; 385 echo '<td align="right">'.number_format($TotalScannedFilesize).'</td>'; 386 echo '<td> </td>'; 387 echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime).'</td>'; 388 echo '<td> </td>'; 389 echo '</tr>'; 390 } 391 echo '</table>'; 392 } else { 393 $errormessage = ob_get_contents(); 394 ob_end_clean(); 395 echo '<b>ERROR: Could not open directory: <u>'.htmlentities($currentfulldir, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'</u></b><br>'; 396 //echo $errormessage.'<br>'; // uncomment for debugging 397 } 398} 399echo PoweredBygetID3().'<br clear="all">'; 400echo '</body></html>'; 401 402 403///////////////////////////////////////////////////////////////// 404 405 406function RemoveAccents($string) { 407 // Revised version by markstewardרotmail*com 408 // Again revised by James Heinrich (19-June-2006) 409 return strtr( 410 strtr( 411 $string, 412 "\x8A\x8E\x9A\x9E\x9F\xC0\xC1\xC2\xC3\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFF", 413 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy' 414 ), 415 array( 416 "\xDE" => 'TH', 417 "\xFE" => 'th', 418 "\xD0" => 'DH', 419 "\xF0" => 'dh', 420 "\xDF" => 'ss', 421 "\x8C" => 'OE', 422 "\x9C" => 'oe', 423 "\xC6" => 'AE', 424 "\xE6" => 'ae', 425 "\xB5" => 'u' 426 ) 427 ); 428} 429 430 431function BitrateColor($bitrate, $BitrateMaxScale=768) { 432 // $BitrateMaxScale is bitrate of maximum-quality color (bright green) 433 // below this is gradient, above is solid green 434 435 $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256 436 $bitrate = round(min(max($bitrate, 1), 256)); 437 $bitrate--; // scale from 1-256kbps to 0-255kbps 438 439 $Rcomponent = max(255 - ($bitrate * 2), 0); 440 $Gcomponent = max(($bitrate * 2) - 255, 0); 441 if ($bitrate > 127) { 442 $Bcomponent = max((255 - $bitrate) * 2, 0); 443 } else { 444 $Bcomponent = max($bitrate * 2, 0); 445 } 446 return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); 447} 448 449function BitrateText($bitrate, $decimals=0, $vbr=false) { 450 return '<span style="color: #'.BitrateColor($bitrate).($vbr ? '; font-weight: bold;' : '').'">'.number_format($bitrate, $decimals).' kbps</span>'; 451} 452 453function string_var_dump($variable) { 454 if (version_compare(PHP_VERSION, '4.3.0', '>=')) { 455 return print_r($variable, true); 456 } 457 ob_start(); 458 var_dump($variable); 459 $dumpedvariable = ob_get_contents(); 460 ob_end_clean(); 461 return $dumpedvariable; 462} 463 464function table_var_dump($variable, $wrap_in_td=false, $encoding='') { 465 global $FileSystemEncoding; 466 $encoding = ($encoding ? $encoding : $FileSystemEncoding); 467 $returnstring = ''; 468 switch (gettype($variable)) { 469 case 'array': 470 $returnstring .= ($wrap_in_td ? '<td>' : ''); 471 $returnstring .= '<table class="dump" cellspacing="0" cellpadding="2">'; 472 foreach ($variable as $key => $value) { 473 $returnstring .= '<tr><td valign="top"><b>'.str_replace("\x00", ' ', $key).'</b></td>'."\n"; 474 $returnstring .= '<td valign="top">'.gettype($value); 475 if (is_array($value)) { 476 $returnstring .= ' ('.count($value).')'; 477 } elseif (is_string($value)) { 478 $returnstring .= ' ('.strlen($value).')'; 479 } 480 //if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { 481 if (($key == 'data') && isset($variable['image_mime'])) { 482 $imageinfo = array(); 483 if ($imagechunkcheck = getid3_lib::GetDataImageSize($value, $imageinfo)) { 484 $returnstring .= '</td>'."\n".'<td><img src="data:'.$variable['image_mime'].';base64,'.base64_encode($value).'" width="'.$imagechunkcheck[0].'" height="'.$imagechunkcheck[1].'"></td></tr>'."\n"; 485 } else { 486 $returnstring .= '</td>'."\n".'<td><i>invalid image data</i></td></tr>'."\n"; 487 } 488 } else { 489 $returnstring .= '</td>'."\n".table_var_dump($value, true, $encoding).'</tr>'."\n"; 490 } 491 } 492 $returnstring .= '</table>'."\n"; 493 $returnstring .= ($wrap_in_td ? '</td>'."\n" : ''); 494 break; 495 496 case 'boolean': 497 $returnstring .= ($wrap_in_td ? '<td class="dump_boolean">' : '').($variable ? 'TRUE' : 'FALSE').($wrap_in_td ? '</td>'."\n" : ''); 498 break; 499 500 case 'integer': 501 $returnstring .= ($wrap_in_td ? '<td class="dump_integer">' : '').$variable.($wrap_in_td ? '</td>'."\n" : ''); 502 break; 503 504 case 'double': 505 case 'float': 506 $returnstring .= ($wrap_in_td ? '<td class="dump_double">' : '').$variable.($wrap_in_td ? '</td>'."\n" : ''); 507 break; 508 509 case 'object': 510 case 'null': 511 $returnstring .= ($wrap_in_td ? '<td>' : '').string_var_dump($variable).($wrap_in_td ? '</td>'."\n" : ''); 512 break; 513 514 case 'string': 515 $returnstring = htmlentities($variable, ENT_QUOTES | ENT_SUBSTITUTE, $encoding); 516 $returnstring = ($wrap_in_td ? '<td class="dump_string">' : '').nl2br($returnstring).($wrap_in_td ? '</td>'."\n" : ''); 517 break; 518 519 default: 520 $imageinfo = array(); 521 if (($imagechunkcheck = getid3_lib::GetDataImageSize($variable, $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { 522 $returnstring .= ($wrap_in_td ? '<td>' : ''); 523 $returnstring .= '<table class="dump" cellspacing="0" cellpadding="2">'; 524 $returnstring .= '<tr><td><b>type</b></td><td>'.image_type_to_mime_type($imagechunkcheck[2]).'</td></tr>'."\n"; 525 $returnstring .= '<tr><td><b>width</b></td><td>'.number_format($imagechunkcheck[0]).' px</td></tr>'."\n"; 526 $returnstring .= '<tr><td><b>height</b></td><td>'.number_format($imagechunkcheck[1]).' px</td></tr>'."\n"; 527 $returnstring .= '<tr><td><b>size</b></td><td>'.number_format(strlen($variable)).' bytes</td></tr></table>'."\n"; 528 $returnstring .= ($wrap_in_td ? '</td>'."\n" : ''); 529 } else { 530 $returnstring .= ($wrap_in_td ? '<td>' : '').nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable))).($wrap_in_td ? '</td>'."\n" : ''); 531 } 532 break; 533 } 534 return $returnstring; 535} 536 537 538function NiceDisplayFiletypeFormat(&$fileinfo) { 539 540 if (empty($fileinfo['fileformat'])) { 541 return '-'; 542 } 543 544 $output = $fileinfo['fileformat']; 545 if (empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { 546 return $output; // 'gif' 547 } 548 if (empty($fileinfo['video']['dataformat']) && !empty($fileinfo['audio']['dataformat'])) { 549 if ($fileinfo['fileformat'] == $fileinfo['audio']['dataformat']) { 550 return $output; // 'mp3' 551 } 552 $output .= '.'.$fileinfo['audio']['dataformat']; // 'ogg.flac' 553 return $output; 554 } 555 if (!empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { 556 if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { 557 return $output; // 'mpeg' 558 } 559 $output .= '.'.$fileinfo['video']['dataformat']; // 'riff.avi' 560 return $output; 561 } 562 if ($fileinfo['video']['dataformat'] == $fileinfo['audio']['dataformat']) { 563 if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { 564 return $output; // 'real' 565 } 566 $output .= '.'.$fileinfo['video']['dataformat']; // any examples? 567 return $output; 568 } 569 $output .= '.'.$fileinfo['video']['dataformat']; 570 $output .= '.'.$fileinfo['audio']['dataformat']; // asf.wmv.wma 571 return $output; 572 573} 574 575function MoreNaturalSort($ar1, $ar2) { 576 if ($ar1 === $ar2) { 577 return 0; 578 } 579 $len1 = strlen($ar1); 580 $len2 = strlen($ar2); 581 $shortest = min($len1, $len2); 582 if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { 583 // the shorter argument is the beginning of the longer one, like "str" and "string" 584 if ($len1 < $len2) { 585 return -1; 586 } elseif ($len1 > $len2) { 587 return 1; 588 } 589 return 0; 590 } 591 $ar1 = RemoveAccents(strtolower(trim($ar1))); 592 $ar2 = RemoveAccents(strtolower(trim($ar2))); 593 $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>''); 594 foreach ($translatearray as $key => $val) { 595 $ar1 = str_replace($key, $val, $ar1); 596 $ar2 = str_replace($key, $val, $ar2); 597 } 598 599 if ($ar1 < $ar2) { 600 return -1; 601 } elseif ($ar1 > $ar2) { 602 return 1; 603 } 604 return 0; 605} 606 607/** 608 * @param string $string 609 * 610 * @return mixed 611 */ 612function PoweredBygetID3($string='') { 613 global $getID3; 614 if (!$string) { 615 $string = '<div style="border: 1px #CCCCCC solid; padding: 5px; margin: 5px 0; float: left; background-color: #EEEEEE; font-size: 8pt; font-family: sans-serif;">Powered by <a href="https://www.getid3.org/"><b>getID3() v<!--GETID3VER--></b><br>https://www.getid3.org/</a><br>Running on PHP v'.PHP_VERSION.' ('.(8 * PHP_INT_SIZE).'-bit, '.(defined('PHP_OS_FAMILY') ? PHP_OS_FAMILY : PHP_OS).')</div>'; 616 } 617 return str_replace('<!--GETID3VER-->', $getID3->version(), $string); 618} 619