module.archive.rar.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // see readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.archive.rar.php //
  11. // module for analyzing RAR files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
  16. exit;
  17. }
  18. class getid3_rar extends getid3_handler
  19. {
  20. /**
  21. * if true use PHP RarArchive extension, if false (non-extension parsing not yet written in getID3)
  22. *
  23. * @var bool
  24. */
  25. public $use_php_rar_extension = true;
  26. /**
  27. * @return bool
  28. */
  29. public function Analyze() {
  30. $info = &$this->getid3->info;
  31. $info['fileformat'] = 'rar';
  32. if ($this->use_php_rar_extension === true) {
  33. if (function_exists('rar_open')) {
  34. if ($rp = rar_open($info['filenamepath'])) {
  35. $info['rar']['files'] = array();
  36. $entries = rar_list($rp);
  37. foreach ($entries as $entry) {
  38. $info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize()));
  39. }
  40. rar_close($rp);
  41. return true;
  42. } else {
  43. $this->error('failed to rar_open('.$info['filename'].')');
  44. }
  45. } else {
  46. $this->error('RAR support does not appear to be available in this PHP installation');
  47. }
  48. } else {
  49. $this->error('PHP-RAR processing has been disabled (set $getid3_rar->use_php_rar_extension=true to enable)');
  50. }
  51. return false;
  52. }
  53. }