Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Zip Class Reference
Inheritance diagram for Zip:
AbstractArchive ArchiveInterface

Public Member Functions

 __construct ()
 
 pack ($source, $destination)
 
 unpack ($source, $destination)
 
- Public Member Functions inherited from AbstractArchive
 getFilename ($source, $withExtension=false)
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractArchive
 _writeFile ($destination, $data)
 
 _readFile ($source)
 

Detailed Description

Zip compressed file archive.

Definition at line 12 of file Zip.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )
Exceptions

Definition at line 17 of file Zip.php.

18  {
19  $type = 'Zip';
20  if (!class_exists('\ZipArchive')) {
21  throw new \Magento\Framework\Exception\LocalizedException(
22  new \Magento\Framework\Phrase('\'%1\' file extension is not supported', [$type])
23  );
24  }
25  }
$type
Definition: item.phtml:13

Member Function Documentation

◆ pack()

pack (   $source,
  $destination 
)

Pack file.

Parameters
string$source
string$destination
Returns
string

Implements ArchiveInterface.

Definition at line 35 of file Zip.php.

36  {
37  $zip = new \ZipArchive();
38  $zip->open($destination, \ZipArchive::CREATE);
39  $zip->addFile($source);
40  $zip->close();
41  return $destination;
42  }
$source
Definition: source.php:23

◆ unpack()

unpack (   $source,
  $destination 
)

Unpack file.

Parameters
string$source
string$destination
Returns
string

Implements ArchiveInterface.

Definition at line 52 of file Zip.php.

53  {
54  $zip = new \ZipArchive();
55  if ($zip->open($source) === true) {
56  $filename = $this->filterRelativePaths($zip->getNameIndex(0) ?: '');
57  if ($filename) {
58  $zip->extractTo(dirname($destination), $filename);
59  rename(dirname($destination).'/'.$filename, $destination);
60  } else {
61  $destination = '';
62  }
63  $zip->close();
64  } else {
65  $destination = '';
66  }
67 
68  return $destination;
69  }
$source
Definition: source.php:23

The documentation for this class was generated from the following file: