demo.simple.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.simple.php - part of getID3() //
  9. // Sample script for scanning a single directory and //
  10. // displaying a few pieces of information for each file //
  11. // see readme.txt for more details //
  12. // ///
  13. /////////////////////////////////////////////////////////////////
  14. die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
  15. echo '<html><head>';
  16. echo '<title>getID3() - /demo/demo.simple.php (sample script)</title>';
  17. echo '<style type="text/css">BODY,TD,TH { font-family: sans-serif; font-size: 9pt; }</style>';
  18. echo '</head><body>';
  19. // include getID3() library (can be in a different directory if full path is specified)
  20. require_once('../getid3/getid3.php');
  21. // Initialize getID3 engine
  22. $getID3 = new getID3;
  23. $DirectoryToScan = '/change/to/directory/you/want/to/scan'; // change to whatever directory you want to scan
  24. $dir = opendir($DirectoryToScan);
  25. echo '<table border="1" cellspacing="0" cellpadding="3">';
  26. echo '<tr><th>Filename</th><th>Artist</th><th>Title</th><th>Bitrate</th><th>Playtime</th></tr>';
  27. while (($file = readdir($dir)) !== false) {
  28. $FullFileName = realpath($DirectoryToScan.'/'.$file);
  29. if ((substr($file, 0, 1) != '.') && is_file($FullFileName)) {
  30. set_time_limit(30);
  31. $ThisFileInfo = $getID3->analyze($FullFileName);
  32. $getID3->CopyTagsToComments($ThisFileInfo);
  33. // output desired information in whatever format you want
  34. echo '<tr>';
  35. echo '<td>'.htmlentities($ThisFileInfo['filenamepath']).'</td>';
  36. echo '<td>' .htmlentities(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<br>', $ThisFileInfo['comments_html']['artist']) : chr(160)).'</td>';
  37. echo '<td>' .htmlentities(!empty($ThisFileInfo['comments_html']['title']) ? implode('<br>', $ThisFileInfo['comments_html']['title']) : chr(160)).'</td>';
  38. echo '<td align="right">'.htmlentities(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : chr(160)).'</td>';
  39. echo '<td align="right">'.htmlentities(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : chr(160)).'</td>';
  40. echo '</tr>';
  41. }
  42. }
  43. echo '</table>';
  44. echo '</body></html>';