Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.96 KB | None | 0 0
  1. <?php
  2. set_time_limit ( 0 );
  3. ob_start();
  4. header('Content-Type: text/html; charset=utf-8');
  5. // check folder
  6. if(!isset($_GET['p'])){
  7. $path = './';
  8. }else{
  9.     $path = $_GET['p'];
  10. }
  11. // check for extensions  
  12. if(isset($_GET['exts'])){
  13.  $exts = $_GET['exts'];
  14. }else{
  15.     $exts = "mp3";
  16. }
  17. function mk_file($filename) {
  18.     if(!is_file($filename)) {
  19.         fclose(fopen($filename,"x"));
  20.         return true;
  21.     } else return false;
  22. }
  23. if(!file_exists("./musiclist.php")){
  24. echo<<<EOL
  25. <style>
  26. body{
  27.     background:#5E7CB0;
  28. }
  29. #music{
  30.     background:#5E7CB0;
  31. }
  32. tr:nth-child(even) {
  33.     background: #C4CEDF
  34. }
  35. tr:nth-child(odd) {
  36.     background: #C8dEEF
  37. }
  38. </style>
  39. <body>
  40. <center>
  41. EOL;
  42. }
  43. $load_file = false;
  44. if(file_exists("./musiclist-$exts.php")){
  45.     $load_file = true;
  46.     $file = "musiclist-$exts.php";
  47. }
  48. if($load_file == true){
  49.     echo "<div id='loaded'>";
  50.     echo file_get_contents($file);
  51.     echo "</div></center>
  52. </body>";
  53. die;
  54. }
  55. function saveit($data,$exts){
  56.     if(!file_exists("./musiclist-$exts.php")){
  57.         mk_file("./musiclist-$exts.php");
  58.     }
  59.     $data = ob_get_contents();
  60.     file_put_contents("./musiclist-$exts.php", $data, FILE_APPEND | LOCK_EX);
  61. }
  62. require_once('./getid3/getid3.php');
  63. $getID3 = new getID3;
  64.     $dir  = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
  65.     $files = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
  66.     foreach ($files as $file=>$mykey) {
  67.         if(is_dir($file)) {
  68.             $directory = $file;
  69.             $mydir = new RecursiveIteratorIterator(
  70.                         new RecursiveRegexIterator(
  71.                             new RecursiveDirectoryIterator($directory,RecursiveDirectoryIterator::FOLLOW_SYMLINKS),
  72.                         '#(?<!/)\.'.$exts.'$|^[^\.]*$#i')
  73.                     ,true);
  74.             foreach ($mydir as $myfile=>$mykey){
  75.                 $result[] = $myfile.'<br />';
  76.                 $filetypes = array("$exts");
  77.                 $filetype = pathinfo($myfile, PATHINFO_EXTENSION);
  78.                 if (in_array(strtolower($filetype), $filetypes)){?>
  79.                     <div><h3><?php echo count($result);?>
  80.                     <span><?php echo  substr(PHP_EOL . $directory . PHP_EOL . PHP_EOL,4);?></span></h3></div>
  81.                     <?php
  82.                     if(in_array(strtolower($filetype), array("mp3"))){                 
  83.                         echo '<table border="1" cellspacing="0" cellpadding="3" id="music">';
  84.                         echo '<tr><th>Filename</th><th>Artist</th><th>Title</th><th>Bitrate</th><th>Playtime</th></tr>';
  85.                     }
  86.                     if (!empty($mydir)) {
  87.                         foreach ($mydir as $d) {
  88.                             if (strpos($d->getFilename(), ".$exts") !== FALSE) {
  89.                                 if (strpos($d->getFilename(), ".mp3") == FALSE) {?>
  90.                                     <div><tr><td><a href="<?php echo $d;?>"><?php echo basename($d->getPath() . DIRECTORY_SEPARATOR . $d->getFilename() . PHP_EOL);?></a></td><td>
  91.                                 <? }
  92.                                 if(strpos($d->getFilename(), ".mp3") !== FALSE){
  93.                                         $ThisFileInfo = $getID3->analyze($d);
  94.                                         getid3_lib::CopyTagsToComments($ThisFileInfo);
  95.                                         echo '<td>'.htmlentities($ThisFileInfo['filenamepath']).'</td>';
  96.                                         echo '<td>'.htmlentities(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<br>', $ThisFileInfo['comments_html']['artist']): chr(160)).'</td>';
  97.                                         echo '<td>'.htmlentities(!empty($ThisFileInfo['comments_html']['title'])  ? implode('<br>', $ThisFileInfo['comments_html']['title']) : chr(160)).'</td>';
  98.                                         echo '<td align="right">'.htmlentities(!empty($ThisFileInfo['audio']['bitrate'])?round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : chr(160)).'</td>';
  99.                                         echo '<td align="right">'.htmlentities(!empty($ThisFileInfo['playtime_string'])?$ThisFileInfo['playtime_string'] : chr(160)).'</td>';
  100.                                 }?></td></tr></div>
  101.                             <?php }
  102.                         }
  103.  
  104.                     }
  105.                     if(strpos($d->getFilename(), ".mp3") !== FALSE){
  106.                         echo '</table>';
  107.                     }
  108.                 }
  109.                 $size=ob_get_length();
  110.                 if ($size > 0.0000){
  111.                     $content = ob_get_contents();
  112.                     saveit($content,$exts);
  113.                     ob_clean();
  114.                 }
  115.             }
  116.         }
  117.     }
  118.     header("location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
  119. ?>
  120. </center>
  121. </body>
  122. <?
  123. ob_end_flush();
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement