PhpZip 은 ZIP 아카이브를 사용한 확장 작업을 위한 PHP 라이브러리입니다.
러시아어 문서
| 버전 | PHP | 선적 서류 비치 |
|---|---|---|
| ^4.0(마스터) | ^7.4|^8.0 | 현재의 |
| ^3.0 | ^5.5|^7.0 | 문서 v3.3 |
PhpZipZipFile 클래스의 메서드 개요php-zip 및 클래스 ZipArchive 필요 없음).php-bz2 확장자를 사용한 BZIP2 압축입니다.ZIP64 지원(파일 크기가 4GB를 초과하거나 아카이브의 항목 수가 65535개를 초과함).주목!
32비트 시스템의 경우
Traditional PKWARE Encryption (ZipCrypto)암호화 방법은 현재 지원되지 않습니다. 가능하면WinZIP AES Encryption암호화 방법을 사용하십시오.
Traditional PKWARE Encryption (ZipCrypto) 및 WinZIP AES Encryption 암호화 방법을 지원합니다.PHP >= 7.4 또는 PHP >= 8.0(64비트 권장).bzip2 .WinZip Aes Encryption 지원을 위한 선택적 php-extension openssl . composer require nelexa/zip
최신 안정 버전:
// create new archive
$ zipFile = new PhpZip ZipFile ();
try {
$ zipFile
-> addFromString ( ' zip/entry/filename ' , ' Is file content ' ) // add an entry from the string
-> addFile ( ' /path/to/file ' , ' data/tofile ' ) // add an entry from the file
-> addDir ( __DIR__ , ' to/path/ ' ) // add files from the directory
-> saveAsFile ( $ outputFilename ) // save the archive to a file
-> close (); // close archive
// open archive, extract, add files, set password and output to browser.
$ zipFile
-> openFile ( $ outputFilename ) // open archive from file
-> extractTo ( $ outputDirExtract ) // extract files to the specified directory
-> deleteFromRegex ( ' ~^.~ ' ) // delete all hidden (Unix) files
-> addFromString ( ' dir/file.txt ' , ' Test file ' ) // add a new entry from the string
-> setPassword ( ' password ' ) // set password for all entries
-> outputAsAttachment ( ' library.jar ' ); // output to the browser without saving to a file
}
catch ( PhpZip Exception ZipException $ e ){
// handle exception
}
finally {
$ zipFile -> close ();
} 다른 예제는 tests/ 폴더에서 찾을 수 있습니다.
Zip 항목 - ZIP 아카이브의 파일 또는 폴더입니다. 아카이브의 각 항목에는 파일 이름, 압축 방법, 암호화 방법, 압축 전 파일 크기, 압축 후 파일 크기, CRC32 등과 같은 특정 속성이 있습니다.
PhpZipZipFile 클래스의 메서드 개요SplFileInfo 추가합니다.SymfonyComponentFinderFinder 의 파일을 ZIP 아카이브에 추가합니다.ZIP 아카이브를 초기화합니다
$ zipFile = new PhpZip ZipFile ();파일에서 zip 아카이브를 엽니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> openFile ( ' file.zip ' );문자열에서 zip 아카이브를 엽니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> openFromString ( $ stringContents );스트림에서 zip 아카이브를 엽니다.
$ stream = fopen ( ' file.zip ' , ' rb ' );
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> openFromStream ( $ stream );아카이브의 항목 수를 반환합니다.
$ zipFile = new PhpZip ZipFile ();
$ count = count ( $ zipFile );
// or
$ count = $ zipFile -> count ();아카이브 파일 목록을 반환합니다.
$ zipFile = new PhpZip ZipFile ();
$ listFiles = $ zipFile -> getListFiles ();
// example array contents:
// array (
// 0 => 'info.txt',
// 1 => 'path/to/file.jpg',
// 2 => 'another path/',
// 3 => '0',
// ) 이름을 사용하여 항목 내용을 반환합니다.
// $entryName = 'path/to/example-entry-name.txt';
$ zipFile = new PhpZip ZipFile ();
$ contents = $ zipFile [ $ entryName ];
// or
$ contents = $ zipFile -> getEntryContents ( $ entryName );아카이브에 항목이 있는지 확인합니다.
// $entryName = 'path/to/example-entry-name.txt';
$ zipFile = new PhpZip ZipFile ();
$ hasEntry = isset ( $ zipFile [ $ entryName ]);
// or
$ hasEntry = $ zipFile -> hasEntry ( $ entryName );아카이브의 항목이 디렉토리인지 확인합니다.
// $entryName = 'path/to/';
$ zipFile = new PhpZip ZipFile ();
$ isDirectory = $ zipFile -> isDirectory ( $ entryName );아카이브 내용을 추출합니다. 디렉터리가 존재해야 합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> extractTo ( $ directory );일부 파일을 디렉터리에 추출합니다. 디렉터리가 존재해야 합니다.
// $toDirectory = '/tmp';
$ extractOnlyFiles = [
' filename1 ' ,
' filename2 ' ,
' dir/dir/dir/ '
];
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> extractTo ( $ toDirectory , $ extractOnlyFiles ); ZipFile 은 반복자입니다. foreach 루프의 모든 항목을 반복할 수 있습니다.
foreach ( $ zipFile as $ entryName => $ contents ){
echo " Filename: $ entryName " . PHP_EOL ;
echo " Contents: $ contents " . PHP_EOL ;
echo ' ----------------------------- ' . PHP_EOL ;
} Iterator 통해 반복할 수 있습니다.
$ iterator = new ArrayIterator ( $ zipFile );
while ( $ iterator -> valid ())
{
$ entryName = $ iterator -> key ();
$ contents = $ iterator -> current ();
echo " Filename: $ entryName " . PHP_EOL ;
echo " Contents: $ contents " . PHP_EOL ;
echo ' ----------------------------- ' . PHP_EOL ;
$ iterator -> next ();
}Zip 아카이브 주석을 반환합니다.
$ zipFile = new PhpZip ZipFile ();
$ commentArchive = $ zipFile -> getArchiveComment ();항목 이름을 사용하여 항목의 설명을 반환합니다.
$ zipFile = new PhpZip ZipFile ();
$ commentEntry = $ zipFile -> getEntryComment ( $ entryName );ZIP 아카이브에 항목을 추가하는 모든 방법을 사용하면 콘텐츠 압축 방법을 지정할 수 있습니다.
다음과 같은 압축 방법을 사용할 수 있습니다.
PhpZipConstantsZipCompressionMethod::STORED - 압축 없음PhpZipConstantsZipCompressionMethod::DEFLATED - 수축 압축PhpZipConstantsZipCompressionMethod::BZIP2 - 확장자가 ext-bz2 인 Bzip2 압축 지정된 경로의 ZIP 아카이브에 파일을 추가합니다.
$ zipFile = new PhpZip ZipFile ();
// $file = '...../file.ext';
// $entryName = 'file2.ext'
$ zipFile -> addFile ( $ file );
// you can specify the name of the entry in the archive (if null, then the last component from the file name is used)
$ zipFile -> addFile ( $ file , $ entryName );
// you can specify a compression method
$ zipFile -> addFile ( $ file , $ entryName , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFile ( $ file , $ entryName , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFile ( $ file , $ entryName , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression ZIP 아카이브에 SplFileInfo 추가합니다.
// $file = '...../file.ext';
// $entryName = 'file2.ext'
$ zipFile = new PhpZip ZipFile ();
$ splFile = new SplFileInfo ( ' README.md ' );
$ zipFile -> addSplFile ( $ splFile );
$ zipFile -> addSplFile ( $ splFile , $ entryName );
// or
$ zipFile [ $ entryName ] = new SplFileInfo ( $ file );
// set compression method
$ zipFile -> addSplFile ( $ splFile , $ entryName , $ options = [
PhpZip Constants ZipOptions:: COMPRESSION_METHOD => PhpZip Constants ZipCompressionMethod:: DEFLATED ,
]); SymfonyComponentFinderFinder 의 파일을 ZIP 아카이브에 추가합니다.
$ finder = new Symfony Component Finder Finder ();
$ finder
-> files ()
-> name ( ' *.{jpg,jpeg,gif,png} ' )
-> name ( ' /^[0-9a-f]./ ' )
-> contains ( ' /lorems+ipsum$/i ' )
-> in ( ' path ' );
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addFromFinder ( $ finder , $ options = [
PhpZip Constants ZipOptions:: COMPRESSION_METHOD => PhpZip Constants ZipCompressionMethod:: DEFLATED ,
PhpZip Constants ZipOptions:: MODIFIED_TIME => new DateTimeImmutable ( ' -1 day 5 min ' )
]);해당 내용을 사용하여 ZIP 아카이브에 파일을 추가합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile [ $ entryName ] = $ contents ;
// or
$ zipFile -> addFromString ( $ entryName , $ contents );
// you can specify a compression method
$ zipFile -> addFromString ( $ entryName , $ contents , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFromString ( $ entryName , $ contents , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFromString ( $ entryName , $ contents , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 스트림의 항목을 ZIP 아카이브에 추가합니다.
$ zipFile = new PhpZip ZipFile ();
// $stream = fopen(..., 'rb');
$ zipFile -> addFromStream ( $ stream , $ entryName );
// or
$ zipFile [ $ entryName ] = $ stream ;
// you can specify a compression method
$ zipFile -> addFromStream ( $ stream , $ entryName , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFromStream ( $ stream , $ entryName , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFromStream ( $ stream , $ entryName , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 새 디렉터리를 추가합니다.
$ zipFile = new PhpZip ZipFile ();
// $path = "path/to/";
$ zipFile -> addEmptyDir ( $ path );
// or
$ zipFile [ $ path ] = null ;배열의 모든 항목을 추가합니다.
$ entries = [
' file.txt ' => ' file contents ' , // add an entry from the string contents
' empty dir/ ' => null , // add empty directory
' path/to/file.jpg ' => fopen ( ' ..../filename ' , ' rb ' ), // add an entry from the stream
' path/to/file.dat ' => new SplFileInfo ( ' ..../filename ' ), // add an entry from the file
];
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addAll ( $ entries );하위 디렉터리 없이 지정된 경로에 있는 디렉터리의 아카이브에 파일을 추가합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addDir ( $ dirName );
// you can specify the path in the archive to which you want to put entries
$ localPath = ' to/path/ ' ;
$ zipFile -> addDir ( $ dirName , $ localPath );
// you can specify a compression method
$ zipFile -> addDir ( $ dirName , $ localPath , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addDir ( $ dirName , $ localPath , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addDir ( $ dirName , $ localPath , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 하위 디렉터리가 있는 지정된 경로의 디렉터리에서 아카이브에 파일을 추가합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addDirRecursive ( $ dirName );
// you can specify the path in the archive to which you want to put entries
$ localPath = ' to/path/ ' ;
$ zipFile -> addDirRecursive ( $ dirName , $ localPath );
// you can specify a compression method
$ zipFile -> addDirRecursive ( $ dirName , $ localPath , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addDirRecursive ( $ dirName , $ localPath , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addDirRecursive ( $ dirName , $ localPath , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 디렉터리 반복자에서 파일을 추가합니다.
// $directoryIterator = new DirectoryIterator($dir); // without subdirectories
// $directoryIterator = new RecursiveDirectoryIterator($dir); // with subdirectories
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addFilesFromIterator ( $ directoryIterator );
// you can specify the path in the archive to which you want to put entries
$ localPath = ' to/path/ ' ;
$ zipFile -> addFilesFromIterator ( $ directoryIterator , $ localPath );
// or
$ zipFile [ $ localPath ] = $ directoryIterator ;
// you can specify a compression method
$ zipFile -> addFilesFromIterator ( $ directoryIterator , $ localPath , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFilesFromIterator ( $ directoryIterator , $ localPath , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFilesFromIterator ( $ directoryIterator , $ localPath , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression일부 파일이 무시되는 예:
$ ignoreFiles = [
' file_ignore.txt ' ,
' dir_ignore/sub dir ignore/ '
];
// $directoryIterator = new DirectoryIterator($dir); // without subdirectories
// $directoryIterator = new RecursiveDirectoryIterator($dir); // with subdirectories
// use PhpZipUtilIteratorIgnoreFilesFilterIterator for non-recursive search
$ zipFile = new PhpZip ZipFile ();
$ ignoreIterator = new PhpZip Util Iterator IgnoreFilesRecursiveFilterIterator (
$ directoryIterator ,
$ ignoreFiles
);
$ zipFile -> addFilesFromIterator ( $ ignoreIterator );하위 디렉터리 없이 glob 패턴으로 디렉터리에서 파일을 추가합니다.
$ globPattern = ' **.{jpg,jpeg,png,gif} ' ; // example glob pattern -> add all .jpg, .jpeg, .png and .gif files
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addFilesFromGlob ( $ dir , $ globPattern );
// you can specify the path in the archive to which you want to put entries
$ localPath = ' to/path/ ' ;
$ zipFile -> addFilesFromGlob ( $ dir , $ globPattern , $ localPath );
// you can specify a compression method
$ zipFile -> addFilesFromGlob ( $ dir , $ globPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFilesFromGlob ( $ dir , $ globPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFilesFromGlob ( $ dir , $ globPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 하위 디렉터리가 있는 glob 패턴으로 디렉터리에서 파일을 추가합니다.
$ globPattern = ' **.{jpg,jpeg,png,gif} ' ; // example glob pattern -> add all .jpg, .jpeg, .png and .gif files
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addFilesFromGlobRecursive ( $ dir , $ globPattern );
// you can specify the path in the archive to which you want to put entries
$ localPath = ' to/path/ ' ;
$ zipFile -> addFilesFromGlobRecursive ( $ dir , $ globPattern , $ localPath );
// you can specify a compression method
$ zipFile -> addFilesFromGlobRecursive ( $ dir , $ globPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFilesFromGlobRecursive ( $ dir , $ globPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFilesFromGlobRecursive ( $ dir , $ globPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 하위 디렉터리 없이 PCRE 패턴으로 디렉터리에서 파일을 추가합니다.
$ regexPattern = ' /.(jpe?g|png|gif)$/si ' ; // example regex pattern -> add all .jpg, .jpeg, .png and .gif files
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> addFilesFromRegex ( $ dir , $ regexPattern );
// you can specify the path in the archive to which you want to put entries
$ localPath = ' to/path/ ' ;
$ zipFile -> addFilesFromRegex ( $ dir , $ regexPattern , $ localPath );
// you can specify a compression method
$ zipFile -> addFilesFromRegex ( $ dir , $ regexPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFilesFromRegex ( $ dir , $ regexPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFilesFromRegex ( $ dir , $ regexPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 하위 디렉터리가 있는 PCRE 패턴으로 디렉터리에서 파일을 추가합니다.
$ regexPattern = ' /.(jpe?g|png|gif)$/si ' ; // example regex pattern -> add all .jpg, .jpeg, .png and .gif files
$ zipFile -> addFilesFromRegexRecursive ( $ dir , $ regexPattern );
// you can specify the path in the archive to which you want to put entries
$ localPath = ' to/path/ ' ;
$ zipFile -> addFilesFromRegexRecursive ( $ dir , $ regexPattern , $ localPath );
// you can specify a compression method
$ zipFile -> addFilesFromRegexRecursive ( $ dir , $ regexPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: STORED ); // No compression
$ zipFile -> addFilesFromRegexRecursive ( $ dir , $ regexPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: DEFLATED ); // Deflate compression
$ zipFile -> addFilesFromRegexRecursive ( $ dir , $ regexPattern , $ localPath , PhpZip Constants ZipCompressionMethod:: BZIP2 ); // BZIP2 compression 해당 이름을 사용하여 아카이브에서 항목을 삭제합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> deleteFromName ( $ entryName );글로벌 패턴을 사용하여 아카이브의 항목을 삭제합니다.
$ globPattern = ' **.{jpg,jpeg,png,gif} ' ; // example glob pattern -> delete all .jpg, .jpeg, .png and .gif files
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> deleteFromGlob ( $ globPattern );PCRE 패턴을 사용하여 아카이브의 항목을 삭제합니다.
$ regexPattern = ' /.(jpe?g|png|gif)$/si ' ; // example regex pattern -> delete all .jpg, .jpeg, .png and .gif files
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> deleteFromRegex ( $ regexPattern );ZIP 아카이브의 모든 항목을 삭제합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> deleteAll ();이름으로 정의된 항목의 이름을 바꿉니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> rename ( $ oldName , $ newName );아카이브의 모든 파일에 대한 압축 수준을 설정합니다.
이 방법은 이 방법을 실행한 후에 추가된 항목에는 적용되지 않습니다.
기본적으로 압축 수준은 5( PhpZipConstantsZipCompressionLevel::NORMAL ) 또는 Deflate 압축을 위해 아카이브에 지정된 압축 수준입니다.
1( PhpZipConstantsZipCompressionLevel::SUPER_FAST )에서 9( PhpZipConstantsZipCompressionLevel::MAXIMUM )까지의 값 범위가 지원됩니다. 숫자가 높을수록 압축이 더 좋고 길어집니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> setCompressionLevel ( PhpZip Constants ZipCompressionLevel:: MAXIMUM );항목의 압축 수준을 이름별로 설정합니다.
1( PhpZipConstantsZipCompressionLevel::SUPER_FAST )에서 9( PhpZipConstantsZipCompressionLevel::MAXIMUM )까지의 값 범위가 지원됩니다. 숫자가 높을수록 압축이 더 좋고 길어집니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> setCompressionLevelEntry ( $ entryName , PhpZip Constants ZipCompressionLevel:: FAST );항목의 압축 방법을 이름별로 설정합니다.
다음과 같은 압축 방법을 사용할 수 있습니다.
PhpZipConstantsZipCompressionMethod::STORED - 압축 없음PhpZipConstantsZipCompressionMethod::DEFLATED - 수축 압축PhpZipConstantsZipCompressionMethod::BZIP2 - 확장자가 ext-bz2 인 Bzip2 압축 $ zipFile = new PhpZip ZipFile ();
$ zipFile -> setCompressionMethodEntry ( $ entryName , PhpZip Constants ZipCompressionMethod:: DEFLATED );ZIP 아카이브의 설명을 설정합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> setArchiveComment ( $ commentArchive );이름으로 정의된 항목의 설명을 설정합니다.
$ zipFile = new PhpZip ZipFile ();
$ zipFile -> setEntryComment ( $ entryName , $ comment );작업을 수행하기 위해 아카이브에서 항목을 선택합니다.
$ zipFile = new PhpZip ZipFile ();
$ matcher = $ zipFile -> matcher ();한 번에 하나씩 아카이브에서 파일 선택:
$ matcher
-> add ( ' entry name ' )
-> add ( ' another entry ' );아카이브에서 여러 파일을 선택하십시오.
$ matcher -> add ([
' entry name ' ,
' another entry name ' ,
' path/ '
]);정규식으로 파일 선택:
$ matcher -> match ( ' ~.jpe?g$~i ' );아카이브의 모든 파일을 선택하십시오:
$ matcher -> all ();count() - 선택한 항목 수를 가져옵니다.
$ count = count ( $ matcher );
// or
$ count = $ matcher -> count ();getMatches() - 선택한 항목 목록을 반환합니다.
$ entries = $ matcher -> getMatches ();
// example array contents: ['entry name', 'another entry name'];호출() - 선택한 항목에 대해 호출 가능한 함수를 호출합니다.
// example
$ matcher -> invoke ( static function ( $ entryName ) use ( $ zipFile ) {
$ newName = preg_replace ( ' ~.(jpe?g)$~i ' , ' .no_optimize.$1 ' , $ entryName );
$ zipFile -> rename ( $ entryName , $ newName );
});선택한 항목에 대한 작업 기능:
$ matcher -> delete (); // remove selected entries from a ZIP archive
$ matcher -> setPassword ( $ password ); // sets a new password for the selected entries
$ matcher -> setPassword ( $ password , $ encryptionMethod ); // sets a new password and encryption method to selected entries
$ matcher -> setEncryptionMethod ( $ encryptionMethod ); // sets the encryption method to the selected entries
$ matcher -> disableEncryption (); // disables encryption for selected entries 암호화 방법에 대한 지원이 구현되었습니다.
PhpZipConstantsZipEncryptionMethod::PKWARE - 기존 PKWARE 암호화(레거시)PhpZipConstantsZipEncryptionMethod::WINZIP_AES_256 - WinZip AES 암호화 256비트(권장)PhpZipConstantsZipEncryptionMethod::WINZIP_AES_192 - WinZip AES 암호화 192비트PhpZipConstantsZipEncryptionMethod::WINZIP_AES_128 - WinZip AES 암호화 128비트 오픈 아카이브의 비밀번호를 설정하세요.
새 항목을 추가하거나 기존 항목을 삭제하는 경우에는 비밀번호를 설정할 필요가 없지만, 콘텐츠를 추출하거나 방법/압축 수준, 암호화 방법을 변경하거나 비밀번호를 변경하려면 이 경우 비밀번호를 지정해야 합니다.
$ zipFile -> setReadPassword ( $ password );이름으로 정의된 항목을 읽기 위한 비밀번호를 가져옵니다.
$ zipFile -> setReadPasswordEntry ( $ entryName , $ password );아카이브의 모든 파일에 대한 새 비밀번호를 설정합니다.
이 방법은 이 방법을 실행한 후에 추가된 항목에는 적용되지 않습니다.
$ zipFile -> setPassword ( $ password );암호화 방법을 설정할 수 있습니다.
$ encryptionMethod = PhpZip Constants ZipEncryptionMethod:: WINZIP_AES_256 ;
$ zipFile -> setPassword ( $ password , $ encryptionMethod );이름으로 정의된 항목의 새 비밀번호를 설정합니다.
$ zipFile -> setPasswordEntry ( $ entryName , $ password );암호화 방법을 설정할 수 있습니다.
$ encryptionMethod = PhpZip Constants ZipEncryptionMethod:: WINZIP_AES_256 ;
$ zipFile -> setPasswordEntry ( $ entryName , $ password , $ encryptionMethod );이미 아카이브에 있는 모든 항목에 대해 암호화를 비활성화합니다.
이 방법은 이 방법을 실행한 후에 추가된 항목에는 적용되지 않습니다.
$ zipFile -> disableEncryption ();이름으로 정의된 항목의 암호화를 비활성화합니다.
$ zipFile -> disableEncryptionEntry ( $ entryName );아카이브에서 수행된 모든 변경 사항을 취소합니다.
$ zipFile -> unchangeAll ();보관 댓글 변경사항을 취소합니다.
$ zipFile -> unchangeArchiveComment ();이름으로 정의된 항목의 변경 사항을 실행 취소합니다.
$ zipFile -> unchangeEntry ( $ entryName );아카이브를 파일에 저장합니다.
$ zipFile -> saveAsFile ( $ filename );아카이브를 스트림에 씁니다.
// $fp = fopen($filename, 'w+b');
$ zipFile -> saveAsStream ( $ fp );ZIP 아카이브를 문자열로 출력합니다.
$ rawZipArchiveBytes = $ zipFile -> outputAsString ();ZIP 아카이브를 브라우저에 출력합니다.
$ zipFile -> outputAsAttachment ( $ outputFilename );Mime 유형을 설정할 수 있습니다.
$ mimeType = ' application/zip ' ;
$ zipFile -> outputAsAttachment ( $ outputFilename , $ mimeType );ZIP 아카이브를 PSR-7 응답으로 출력합니다.
출력 방법은 모든 PSR-7 호환 프레임워크에서 사용할 수 있습니다.
// $response = ....; // instance PsrHttpMessageResponseInterface
$ zipFile -> outputAsPsr7Response ( $ response , $ outputFilename );Mime 유형을 설정할 수 있습니다.
$ mimeType = ' application/zip ' ;
$ zipFile -> outputAsPsr7Response ( $ response , $ outputFilename , $ mimeType );ZIP 아카이브를 Symfony Response로 출력합니다.
출력 방법은 Symfony 프레임워크에서 사용할 수 있습니다.
$ response = $ zipFile -> outputAsSymfonyResponse ( $ outputFilename );Mime 유형을 설정할 수 있습니다.
$ mimeType = ' application/zip ' ;
$ response = $ zipFile -> outputAsSymfonyResponse ( $ outputFilename , $ mimeType );Symfony Controller에서의 사용 예:
<?php
namespace App Controller ;
use PhpZip ZipFile ;
use Symfony Component HttpFoundation Response ;
use Symfony Component Routing Annotation Route ;
class DownloadZipController
{
/**
* @Route("/downloads/{id}")
*
* @throws PhpZipExceptionZipException
*/
public function __invoke ( string $ id ): Response
{
$ zipFile = new ZipFile ();
$ zipFile [ ' file ' ] = ' contents ' ;
$ outputFilename = $ id . ' .zip ' ;
return $ zipFile -> outputAsSymfonyResponse ( $ outputFilename );
}
}변경 사항을 저장하고 변경된 아카이브를 다시 엽니다.
$ zipFile -> rewrite ();아카이브를 닫습니다.
$ zipFile -> close ();개발을 위한 종속성을 설치합니다.
composer install --dev테스트를 실행합니다.
vendor/bin/phpunit변경 사항은 릴리스 페이지에 문서화되어 있습니다.
composer.json 파일의 주 버전을 ^4.0 으로 업데이트합니다.
{
"require" : {
"nelexa/zip" : " ^4.0 "
}
} 그런 다음 Composer 사용하여 업데이트를 설치합니다.
composer update nelexa/zip새 버전인 BC 에서 작동하도록 코드를 업데이트하세요.
zipalign 기능이 제거되었습니다. 이 기능은 별도의 패키지 nelexa/apkfile 에 배치됩니다. composer.json 파일의 주 버전을 ^3.0 으로 업데이트합니다.
{
"require" : {
"nelexa/zip" : " ^3.0 "
}
} 그런 다음 Composer 사용하여 업데이트를 설치합니다.
composer update nelexa/zip새 버전에서 작동하도록 코드를 업데이트하세요.
ZipOutputFile ZipFile 에 병합되고 제거되었습니다.new PhpZipZipOutputFile() new PhpZipZipFile() 로PhpZipZipFile::openFromFile($filename); (new PhpZipZipFile())->openFile($filename);PhpZipZipOutputFile::openFromFile($filename); (new PhpZipZipFile())->openFile($filename);PhpZipZipFile::openFromString($contents); (new PhpZipZipFile())->openFromString($contents);PhpZipZipFile::openFromStream($stream); (new PhpZipZipFile())->openFromStream($stream);PhpZipZipOutputFile::create() new PhpZipZipFile() 로PhpZipZipOutputFile::openFromZipFile(PhpZipZipFile $zipFile) > (new PhpZipZipFile())->openFile($filename);addFromFile 에서 addFile 로setLevel 에서 setCompressionLevel 로ZipFile::setPassword ZipFile::withReadPassword 로ZipOutputFile::setPassword ZipFile::withNewPassword 로ZipOutputFile::disableEncryptionAllEntries to ZipFile::withoutPasswordZipOutputFile::setComment ZipFile::setArchiveComment 로ZipFile::getComment ZipFile::getArchiveComment 로addDir , addFilesFromGlob , addFilesFromRegex 메소드에 대한 서명이 변경되었습니다.getLevelsetCompressionMethodsetEntryPassword