module.archive.rar.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. * @var bool
  22. */
  23. public $option_use_rar_extension = false;
  24. /**
  25. * @return bool
  26. */
  27. public function Analyze() {
  28. $info = &$this->getid3->info;
  29. $info['fileformat'] = 'rar';
  30. if ($this->option_use_rar_extension === true) {
  31. if (function_exists('rar_open')) {
  32. if ($rp = rar_open($info['filenamepath'])) {
  33. $info['rar']['files'] = array();
  34. $entries = rar_list($rp);
  35. foreach ($entries as $entry) {
  36. $info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize()));
  37. }
  38. rar_close($rp);
  39. return true;
  40. } else {
  41. $this->error('failed to rar_open('.$info['filename'].')');
  42. }
  43. } else {
  44. $this->error('RAR support does not appear to be available in this PHP installation');
  45. }
  46. } else {
  47. $this->error('PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)');
  48. }
  49. return false;
  50. }
  51. }