Decompressing LZMA with PHP

泄露秘密 提交于 2020-01-14 08:23:13

问题


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:


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.



来源:https://stackoverflow.com/questions/32786485/decompressing-lzma-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!