Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompressing LZMA with PHP

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.

like image 420
hedgehog90 Avatar asked Sep 25 '15 16:09

hedgehog90


1 Answers

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.

like image 192
David Komanek Avatar answered Sep 22 '22 04:09

David Komanek