Decompressing LZMA with PHP

2019-06-18 04:36发布

I have a load of SWF files compressed with LZMA that I would like to programatically decompress and read with PHP on my server. Can someone direct me to a PHP LZMA SDK? I've googled for it, but have so far found nothing but references to a broken link (7z extension for php?)

I have a working python module that manages to read headers of LZMA compressed SWFs but it requires a module called pyLZMA which doesn't seem to want to install on my server, and getting it to work locally was a massive pain in the arse so I'd much prefer a PHP solution if one exists.

1条回答
ら.Afraid
2楼-- · 2019-06-18 05:26

There is a library called PHP-SevenZipArchive which is a wrapper to 7za and 7zr binaries. Simple test scenario working for me in linux:

install p7zip package (yum install p7zip or similar)

create test compressed file in linux shell

echo "Compressed data" | lzma -z > compressed.string

download and unzip PHP-SevenZipArchive

wget https://github.com/cmanley/PHP-SevenZipArchive/archive/master.zip
unzip master.zip

create directory for decompressed output

mkdir out

create test php file

<?php
require "./PHP-SevenZipArchive-master/SevenZipArchive.php";
$archive = new SevenZipArchive('compressed.string', array('binary'=>'/usr/bin/7za'));
$archive->extractTo('out');
?>

php -f ./index.php will create file out/compressed

cat out/compressed

Compressed data

NOTE: My previous answer was deleted by moderators for its poor quality, although I already got a positive reputation for it. So I rewrote it completely in a detailed way. Hope this helps even more.

查看更多
登录 后发表回答