Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/filestorage/zip_archive.php b/lib/filestorage/zip_archive.php
- index 61b7d336d65..9fbfaa919b0 100644
- --- a/lib/filestorage/zip_archive.php
- +++ b/lib/filestorage/zip_archive.php
- @@ -254,6 +254,19 @@ class zip_archive extends file_archive {
- return $this->za->getStream($name);
- }
- + public function extract_to($destination, $index) {
- + if (!isset($this->za)) {
- + return false;
- + }
- +
- + $name = $this->za->getNameIndex($index);
- + if ($name === false) {
- + return false;
- + }
- +
- + return $this->za->extractTo($destination, $name);
- + }
- +
- /**
- * Returns file information.
- *
- diff --git a/lib/filestorage/zip_packer.php b/lib/filestorage/zip_packer.php
- index 47395f73b24..3a13a0e180e 100644
- --- a/lib/filestorage/zip_packer.php
- +++ b/lib/filestorage/zip_packer.php
- @@ -341,24 +341,13 @@ class zip_packer extends file_packer {
- }
- $newfile = "$newdir/$filename";
- - if (!$fp = fopen($newfile, 'wb')) {
- - $processed[$name] = 'Can not write target file'; // TODO: localise
- - $success = false;
- - continue;
- - }
- - if (!$fz = $ziparch->get_stream($info->index)) {
- - $processed[$name] = 'Can not read file from zip archive'; // TODO: localise
- +
- + if (!$fz = $ziparch->extract_to($pathname, $info->index)) {
- + $processed[$name] = 'Can not extract file from zip archive to destination'; // TODO: localise
- $success = false;
- - fclose($fp);
- continue;
- }
- - while (!feof($fz)) {
- - $content = fread($fz, 262143);
- - fwrite($fp, $content);
- - }
- - fclose($fz);
- - fclose($fp);
- if (filesize($newfile) !== $size) {
- $processed[$name] = 'Unknown error during zip extraction'; // TODO: localise
- $success = false;
Advertisement
Add Comment
Please, Sign In to add comment