stronk7

Untitled

Aug 10th, 2020
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. diff --git a/lib/filestorage/zip_archive.php b/lib/filestorage/zip_archive.php
  2. index 61b7d336d65..9fbfaa919b0 100644
  3. --- a/lib/filestorage/zip_archive.php
  4. +++ b/lib/filestorage/zip_archive.php
  5. @@ -254,6 +254,19 @@ class zip_archive extends file_archive {
  6. return $this->za->getStream($name);
  7. }
  8.  
  9. + public function extract_to($destination, $index) {
  10. + if (!isset($this->za)) {
  11. + return false;
  12. + }
  13. +
  14. + $name = $this->za->getNameIndex($index);
  15. + if ($name === false) {
  16. + return false;
  17. + }
  18. +
  19. + return $this->za->extractTo($destination, $name);
  20. + }
  21. +
  22. /**
  23. * Returns file information.
  24. *
  25. diff --git a/lib/filestorage/zip_packer.php b/lib/filestorage/zip_packer.php
  26. index 47395f73b24..3a13a0e180e 100644
  27. --- a/lib/filestorage/zip_packer.php
  28. +++ b/lib/filestorage/zip_packer.php
  29. @@ -341,24 +341,13 @@ class zip_packer extends file_packer {
  30. }
  31.  
  32. $newfile = "$newdir/$filename";
  33. - if (!$fp = fopen($newfile, 'wb')) {
  34. - $processed[$name] = 'Can not write target file'; // TODO: localise
  35. - $success = false;
  36. - continue;
  37. - }
  38. - if (!$fz = $ziparch->get_stream($info->index)) {
  39. - $processed[$name] = 'Can not read file from zip archive'; // TODO: localise
  40. +
  41. + if (!$fz = $ziparch->extract_to($pathname, $info->index)) {
  42. + $processed[$name] = 'Can not extract file from zip archive to destination'; // TODO: localise
  43. $success = false;
  44. - fclose($fp);
  45. continue;
  46. }
  47.  
  48. - while (!feof($fz)) {
  49. - $content = fread($fz, 262143);
  50. - fwrite($fp, $content);
  51. - }
  52. - fclose($fz);
  53. - fclose($fp);
  54. if (filesize($newfile) !== $size) {
  55. $processed[$name] = 'Unknown error during zip extraction'; // TODO: localise
  56. $success = false;
Advertisement
Add Comment
Please, Sign In to add comment