PHPGangsta - Der praktische PHP Blog

PHP Blog von PHPGangsta


Archive for the ‘SevenZipArchive’ tag

Archivierung mit 7-Zip in PHP

with 8 comments

Um Zip-Dateien zu packen und zu entpacken wird häufig die ZipArchive-Klasse in PHP genutzt, das ist einfach und unkompliziert, Beispiele dafür befindet sich im PHP Manual. Ein weiteres verbreitetes Komprimierungsformat ist RAR, doch PHP kann damit nativ nicht umgehen. Nehmen wir an wir bekommen RAR-Dateien hochgeladen und wollen sie entpacken. Wie machen wir das?

Wir benötigen also ein externes Programm, das mit RAR-Archiven umgehen kann, und ein weit verbreitetes Open-Source-Programm ist 7-Zip. 7-Zip beherrscht noch einige weitere Formate, unter anderem auch sein eigenes 7z-Format. Es ist teilweise besser als das kommerzielle WinZip. Hier die Haupt-Features von der Webseite:

  • High compression ratio in 7z format with LZMA and LZMA2 compression
  • Supported formats:
    • Packing / unpacking: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM
    • Unpacking only: ARJ, CAB, CHM, CPIO, CramFS, DEB, DMG, FAT, HFS, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, RAR, RPM, SquashFS, UDF, VHD, WIM, XAR and Z.
  • For ZIP and GZIP formats, 7-Zip provides a compression ratio that is 2-10 % better than the ratio provided by PKZip and WinZip
  • Strong AES-256 encryption in 7z and ZIP formats
  • Self-extracting capability for 7z format
  • Integration with Windows Shell
  • Powerful File Manager
  • Powerful command line version
  • Plugin for FAR Manager
  • Localizations for 79 languages

Es gibt also auch ein Kommandozeilentool, das wir aus PHP heraus nutzen können! Dann mal auf:

Zuerst laden wir uns 7-Zip herunter, entweder für Linux oder für Windows (7-Zip Command Line Version). Was wir benötigen ist die 7za Executable bzw. die 7za.exe

Weiterlesen »

Written by Michael Kliewe

September 21st, 2011 at 9:57 am

Posted in PHP

Tagged with , , , ,