PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/oms_user/modules/subir_cunia/actions/getid3/getid3.check.php

https://github.com/gaea/oms
PHP | 245 lines | 194 code | 22 blank | 29 comment | 51 complexity | db17a0800b74ad9f02ad139496046b12 MD5 | raw file
  1. <?php
  2. ////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <getid3@silisoftware.com> //
  4. // available at http://www.silisoftware.com ///
  5. ////////////////////////////////////////////////////////////
  6. // //
  7. // check.php - part of getID3() //
  8. // sample script for checking remote and local files //
  9. // See getid3.readme.txt for more details //
  10. // //
  11. ////////////////////////////////////////////////////////////
  12. include_once('getid3.php');
  13. include_once(GETID3_INCLUDEPATH.'getid3.functions.php'); // Function library
  14. $old_error_reporting = error_reporting(E_ALL);
  15. // $old_error_reporting = error_reporting(E_ALL & ~(E_NOTICE));
  16. if (isset($_GET['filename'])) {
  17. // support for running with register globals turned off
  18. // while maintaing pre-PHP4.1.0 compatibility
  19. // thanks to reel_taz@users.sourceforge.net
  20. $filename = $_GET['filename'];
  21. }
  22. if (isset($_GET['listdirectory'])) {
  23. $listdirectory = $_GET['listdirectory'];
  24. }
  25. if (isset($_GET['deletefile'])) {
  26. $deletefile = $_GET['deletefile'];
  27. }
  28. echo '<HTML><HEAD><TITLE>getID3() - getid3.check.php (sample script)</TITLE></HEAD><BODY>';
  29. if (isset($deletefile)) {
  30. if (file_exists($deletefile)) {
  31. if (unlink($deletefile)) {
  32. echo '<SCRIPT LANGUAGE="JavaScript">alert("Successfully deleted '.addslashes($deletefile).'");</SCRIPT>';
  33. } else {
  34. echo '<SCRIPT LANGUAGE="JavaScript">alert("FAILED to delete '.addslashes($deletefile).'");</SCRIPT>';
  35. }
  36. } else {
  37. echo '<SCRIPT LANGUAGE="JavaScript">alert("'.addslashes($deletefile).' does not exist - cannot delete");</SCRIPT>';
  38. }
  39. }
  40. if (isset($filename)) {
  41. $starttime = getmicrotime();
  42. if (isset($assumeFormat)) {
  43. $MP3fileInfo = GetAllMP3info($filename, $assumeFormat);
  44. } else {
  45. $MP3fileInfo = GetAllMP3info($filename, '');
  46. if (!isset($MP3fileInfo['fileformat']) || ($MP3fileInfo['fileformat'] == '')) {
  47. $formatExtensions = array('mp3'=>'mp3', 'ogg'=>'ogg', 'zip'=>'zip', 'wav'=>'riff', 'avi'=>'riff', 'mid'=>'midi', 'mpg'=>'mpeg', 'jpg'=>'image', 'gif'=>'image', 'png'=>'image');
  48. if (isset($formatExtensions[fileextension($filename)])) {
  49. $MP3fileInfo = GetAllMP3info($filename, $formatExtensions[fileextension($filename)]);
  50. }
  51. }
  52. }
  53. $listdirectory = dirname($filename);
  54. if (!is_dir($listdirectory)) {
  55. // Directory names with single quotes or double quotes in them will likely come out addslashes()'d
  56. // so this will replace \' with ' (can't use stripslashes(), that would get rid of all slashes!)
  57. $listdirectory = str_replace(chr(92).chr(92), chr(92), $listdirectory); // \\ -> \
  58. $listdirectory = str_replace(chr(92).chr(39), chr(39), $listdirectory); // \' -> '
  59. $listdirectory = str_replace(chr(92).chr(34), chr(34), $listdirectory); // \" -> "
  60. }
  61. $listdirectory = realpath($listdirectory); // get rid of /../../ references
  62. if (is_dir(str_replace('\\', '/', $listdirectory))) {
  63. // this mostly just gives a consistant look to Windows and *nix filesystems
  64. // (windows uses \ as directory seperator, *nix uses /)
  65. $listdirectory = str_replace('\\', '/', $listdirectory.'/');
  66. }
  67. echo 'Browse: <A HREF="'.$PHP_SELF.'?listdirectory='.urlencode($listdirectory).'">'.$listdirectory.'</A><BR>';
  68. echo 'Parse this file as: ';
  69. $allowedFormats = array('zip', 'ogg', 'riff', 'mpeg', 'midi', 'image', 'mp3');
  70. foreach ($allowedFormats as $possibleFormat) {
  71. if (isset($assumeFormat) && ($assumeFormat == $possibleFormat)) {
  72. echo '<B>'.$possibleFormat.'</B> | ';
  73. } else {
  74. echo '<A HREF="'.$PHP_SELF.'?filename='.urlencode($filename).'&assumeFormat='.$possibleFormat.'">'.$possibleFormat.'</A> | ';
  75. }
  76. }
  77. if (isset($assumeFormat)) {
  78. echo '<A HREF="'.$PHP_SELF.'?filename='.urlencode($filename).'">default</A><BR>';
  79. } else {
  80. echo '<B>default</B><BR>';
  81. }
  82. echo table_var_dump($MP3fileInfo);
  83. $endtime = getmicrotime();
  84. echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.<BR>';
  85. } else {
  86. if (!isset($listdirectory)) {
  87. $listdirectory = '.';
  88. }
  89. // if (!is_dir($listdirectory) && is_dir(str_replace(chr(92).chr(39), chr(39), $listdirectory))) {
  90. if (!is_dir($listdirectory)) {
  91. // Directory names with single quotes or double quotes in them will likely come out addslashes()'d
  92. // so this will replace \' with ' (can't use stripslashes(), that would get rid of all slashes!)
  93. $listdirectory = str_replace(chr(92).chr(92), chr(92), $listdirectory); // \\ -> \
  94. $listdirectory = str_replace(chr(92).chr(39), chr(39), $listdirectory); // \' -> '
  95. $listdirectory = str_replace(chr(92).chr(34), chr(34), $listdirectory); // \" -> "
  96. }
  97. $listdirectory = realpath($listdirectory); // get rid of /../../ references
  98. $currentfulldir = $listdirectory.'/';
  99. if (is_dir(str_replace('\\', '/', $listdirectory))) {
  100. // this mostly just gives a consistant look to Windows and *nix filesystems
  101. // (windows uses \ as directory seperator, *nix uses /)
  102. $currentfulldir = str_replace('\\', '/', $listdirectory.'/');
  103. }
  104. if ($handle = @opendir($listdirectory)) {
  105. echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces
  106. echo 'Processing';
  107. $starttime = getmicrotime();
  108. //while (($file = readdir($handle)) !== FALSE) {
  109. while ($file = readdir($handle)) {
  110. set_time_limit(10); // allocate another 10 seconds (to the usual 30-second script execution time limit) to process this file
  111. echo '.'; // progress indicator dot
  112. // echo '<HR>'.$file.'<br>';
  113. flush(); // make sure the dot is show, otherwise it's useless
  114. if (is_dir(str_replace('//', '/', $currentfulldir))) {
  115. // if the directory name contains "weird" things like
  116. // " or ' or \" or \' etc then this might cause problems
  117. // in which case just use un-manipulated $listdirectory
  118. $currentfilename = str_replace('//', '/', $currentfulldir).$file;
  119. } else {
  120. $currentfilename = $listdirectory.'/'.$file;
  121. }
  122. // symbolic-link-resolution enhancements by davidbullock@tech-center.com
  123. $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link
  124. $TargetObjectType = filetype($TargetObject); // Check file type without examining extension
  125. if($TargetObjectType == 'dir') {
  126. $DirectoryContents["$currentfulldir"]['dir']["$file"]['filesize'] = '-';
  127. $DirectoryContents["$currentfulldir"]['dir']["$file"]['playtime_string'] = '-';
  128. } else if ($TargetObjectType == 'file') {
  129. $fileinformation = GetAllMP3info($currentfilename, FALSE);
  130. if (!isset($fileinformation['fileformat']) || ($fileinformation['fileformat'] == '')) {
  131. // auto-detect couldn't find the file format (probably corrupt header?), re-scan based on extension, if applicable
  132. $formatExtensions = array('mp3'=>'mp3', 'ogg'=>'ogg', 'zip'=>'zip', 'wav'=>'riff', 'avi'=>'riff', 'mid'=>'midi', 'mpg'=>'mpeg', 'jpg'=>'image', 'gif'=>'image', 'png'=>'image');
  133. if (isset($formatExtensions[fileextension($currentfilename)])) {
  134. $fileinformation = GetAllMP3info($currentfilename, $formatExtensions[fileextension($currentfilename)]);
  135. }
  136. }
  137. if (isset($fileinformation['fileformat']) && $fileinformation['fileformat']) {
  138. $DirectoryContents["$currentfulldir"]['known']["$file"] = $fileinformation;
  139. } else {
  140. $DirectoryContents["$currentfulldir"]['other']["$file"]['filesize'] = filesize($currentfilename);
  141. $DirectoryContents["$currentfulldir"]['other']["$file"]['playtime_string'] = '-';
  142. }
  143. }
  144. }
  145. $endtime = getmicrotime();
  146. closedir($handle);
  147. echo 'done<BR>';
  148. echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.<BR>';
  149. flush();
  150. echo '<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="3">';
  151. echo '<TR BGCOLOR="#CCCCDD"><TH COLSPAN="11">Files in '.$currentfulldir.'</TH></TR>';
  152. echo '<TR BGCOLOR="#CCCCEE"><TH>Filename</TH><TH>File Size</TH><TH>Format</TH><TH>Playtime</TH><TH>Artist</TH><TH>Title</TH><TH>ID3v1</TH><TH>ID3v2</TH><TH>Lyrics3</TH><TH>Edit</TH><TH>Delete</TH></TR>';
  153. $rowcounter = 0;
  154. foreach ($DirectoryContents as $dirname => $val) {
  155. if (is_array($DirectoryContents["$dirname"]['dir'])) {
  156. // ksort($DirectoryContents["$dirname"]['dir']);
  157. uksort($DirectoryContents["$dirname"]['dir'], 'MoreNaturalSort');
  158. foreach ($DirectoryContents["$dirname"]['dir'] as $filename => $fileinfo) {
  159. echo '<TR BGCOLOR="#'.(($rowcounter++ % 2) ? 'FFCCCC' : 'EEBBBB').'">';
  160. echo '<TD><A HREF="'.$PHP_SELF.'?listdirectory='.urlencode($dirname.$filename).'"><B>'.$filename.'</B></A></TD>';
  161. echo '<TD ALIGN="CENTER">&nbsp;'.$fileinfo['filesize'].'</TD>';
  162. echo '<TD ALIGN="RIGHT">&nbsp;'.(isset($fileinfo['fileformat']) ? $fileinfo['fileformat'] : '').'</TD>';
  163. echo '<TD ALIGN="RIGHT">&nbsp;'.$fileinfo['playtime_string'].'</TD>';
  164. echo '<TD ALIGN="LEFT">&nbsp;</TD>';
  165. echo '<TD ALIGN="LEFT">&nbsp;</TD>';
  166. echo '<TD ALIGN="LEFT">&nbsp;</TD>';
  167. echo '<TD ALIGN="LEFT">&nbsp;</TD>';
  168. echo '<TD ALIGN="LEFT">&nbsp;</TD>';
  169. echo '<TD ALIGN="LEFT">&nbsp;</TD>';
  170. echo '<TD ALIGN="LEFT">&nbsp;</TD></TR>';
  171. }
  172. }
  173. if (isset($DirectoryContents["$dirname"]['known']) && is_array($DirectoryContents["$dirname"]['known'])) {
  174. // ksort($DirectoryContents["$dirname"]['known']);
  175. uksort($DirectoryContents["$dirname"]['known'], 'MoreNaturalSort');
  176. foreach ($DirectoryContents["$dirname"]['known'] as $filename => $fileinfo) {
  177. echo '<TR BGCOLOR="#'.(($rowcounter++ % 2) ? 'DDDDDD' : 'EEEEEE').'">';
  178. echo '<TD><A HREF="'.$PHP_SELF.'?filename='.urlencode($dirname.$filename).'" TITLE="View detailed analysis">'.$filename.'</A></TD>';
  179. echo '<TD ALIGN="RIGHT">&nbsp;'.number_format($fileinfo['filesize']).'</TD>';
  180. echo '<TD ALIGN="RIGHT">&nbsp;'.$fileinfo['fileformat'].'</TD>';
  181. echo '<TD ALIGN="RIGHT">&nbsp;'.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '').'</TD>';
  182. echo '<TD ALIGN="LEFT">&nbsp;'.(isset($fileinfo['artist']) ? $fileinfo['artist'] : '').'</TD>';
  183. echo '<TD ALIGN="LEFT">&nbsp;'.(isset($fileinfo['title']) ? $fileinfo['title'] : '').'</TD>';
  184. echo '<TD ALIGN="LEFT">&nbsp;'.(isset($fileinfo['id3']['id3v1']) ? 'Y' : '').'</TD>';
  185. echo '<TD ALIGN="LEFT">&nbsp;'.(isset($fileinfo['id3']['id3v2']) ? 'Y' : '').'</TD>';
  186. echo '<TD ALIGN="LEFT">&nbsp;'.(isset($fileinfo['lyrics3']) ? 'Y' : '').'</TD>';
  187. echo '<TD ALIGN="LEFT">&nbsp;';
  188. if ($fileinfo['fileformat'] == 'mp3') {
  189. echo '<A HREF="getid3.write.php?EditorFilename='.urlencode($dirname.$filename).'" TITLE="Edit ID3 tag">edit&nbsp;ID3';
  190. }
  191. echo '</TD>';
  192. echo '<TD ALIGN="LEFT">&nbsp;<A HREF="'.$PHP_SELF.'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes($dirname.$filename).'? \n(this action cannot be un-done)\');" TITLE="Permanently delete '."\n".FixTextFields($filename)."\n".' from'."\n".' '.FixTextFields($dirname).'">delete</A></TD>';
  193. echo '</TR>';
  194. }
  195. }
  196. if (isset($DirectoryContents["$dirname"]['other']) && is_array($DirectoryContents["$dirname"]['other'])) {
  197. // ksort($DirectoryContents["$dirname"]['other']);
  198. uksort($DirectoryContents["$dirname"]['other'], 'MoreNaturalSort');
  199. foreach ($DirectoryContents["$dirname"]['other'] as $filename => $fileinfo) {
  200. echo '<TR BGCOLOR="#'.(($rowcounter++ % 2) ? 'BBBBDD' : 'CCCCFF').'">';
  201. echo '<TD><A HREF="'.$PHP_SELF.'?filename='.urlencode($dirname.$filename).'"><I>'.$filename.'</I></A></TD>';
  202. echo '<TD ALIGN="RIGHT">&nbsp;'.number_format($fileinfo['filesize']).'</TD>';
  203. echo '<TD ALIGN="RIGHT">&nbsp;'.(isset($fileinfo['fileformat']) ? $fileinfo['fileformat'] : '').'</TD>';
  204. echo '<TD ALIGN="RIGHT">&nbsp;'.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '').'</TD>';
  205. echo '<TD ALIGN="LEFT">&nbsp;</TD>'; // Artist
  206. echo '<TD ALIGN="LEFT">&nbsp;</TD>'; // Title
  207. echo '<TD ALIGN="LEFT">&nbsp;</TD>'; // ID3v1
  208. echo '<TD ALIGN="LEFT">&nbsp;</TD>'; // ID3v2
  209. echo '<TD ALIGN="LEFT">&nbsp;</TD>'; // Lyrics3
  210. echo '<TD ALIGN="LEFT">&nbsp;</TD>'; // Edit
  211. echo '<TD ALIGN="LEFT">&nbsp;<A HREF="'.$PHP_SELF.'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename).'" 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>';
  212. echo '</TR>';
  213. }
  214. }
  215. }
  216. echo '</TABLE>';
  217. } else {
  218. echo '<B>ERROR: Could not open directory: <U>'.$currentfulldir.'</U></B><BR>';
  219. }
  220. }
  221. echo '</BODY></HTML>';
  222. error_reporting($old_error_reporting);
  223. ?>