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.
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.
Related
I'm extracting server side .zip using this:
<?php
$unzip = shell_exec("unzip zipp1.zip");
?>
It's working fine, but it doesn't overwrite existing files (and I need it!).
Everything is in the same folder, chmod 777.
Can I add something to fix?
Tnx!
If you really need to use shell, you can write unzip -o zipp1.zip.
However, PHP has a library for working with Zip archives, called ZipArchive: http://php.net/manual/en/class.ziparchive.php
There you can extractTo which overwrites by default: http://php.net/manual/en/ziparchive.extractto.php
It's usually a good security practice to disable shell_exec(), so using PHP's libraries is recommended.
I have a php upload script that converts MP3 files after they have been uploaded. I am keeping the mp3 file which is why I am doing it afterwards. A copy is created and then that is converted to ogg. The problem i am having is with FFMPEG as it is just not doing anything. I have never used FFMPEG or a tool like it before, nor have I used PHP's exec() function so I really have no idea how to use it but I have had a thorough look around for my answer before I came here.
exec("ffmpeg -i ".$target_path."".$hash_filename.".".$path_extension." ".$hash_filename.".ogg");
What the function could look like with data instead of variables:
ffmpeg -i ../uploads/ee78d5deb564901626067cc0008456ed.mp3 ee78d5deb564901626067cc0008456ed.ogg
I have checked with SSH and FFMPEG is located under the usual usr/bin/ffmpeg. I wondered if I should be targeting the file from where FFMPEG is or where the phpscript is but I have had no luck with either. Perhaps I am still targeting it from the wrong place?
I have checked and the codecs required for mp3 to ogg conversion are installed. I did also try adding those codecs into the command but the same thing happened. I understand FFMPEG automatically chooses which codecs to use so I ommited them.
I have a problem. I have the service which is giving me .exe file which they claim is in fact zip archive. A self-extracting archive.
Problem is that I am downloading that with my app (php) to server and need to extract it there witout downloading to local computer.
I have tried download .exe file to local computer - it is self extracting on windows to /temp dir and than self launching FLASH player.
$zip = zip_open($myfile); gives in print_r($zip): 1
zip->open gives no results either.
change .exe to .zip doesn't let winzip or other kind of un-packer on windows to open it - .exe cannot be opened by winzip too.
Now I have no idea how to deal with it. If anybody can advise please.
Try to execute the program as an executable with the system command
Executing files from an external source you don't trust 100% is never a good idea.
The info-zip version of zip allows you to remove the SFX stub from a self-extracting zip file (with the -J flag) converting it back into a normal zip file.
Source code is freely available.
Making a self-extracting zip file is a matter of prepending a zip file with the SFX binary code, then appending the size of the binary stub to the resulting file - but I'm not sure how the data is represented - but a bit of reverse-engineering the available code should make this clear.
Well... if your PHP server is Windows you shouldn't have a problem doing it as a system command. Otherwise, it's a little more tricky. I hear that the unzip system command will unzip self-extracting zip files, but I don't have access to a Linux box at the moment to try it out.
If you're on shared hosting, chances are you can't do it.
Well if you think after executing the exe file, it will extract its content, then you can use exec function to run the .exe files like the one below:
exec("d:\\example\\php\_exe\\1436.exe");
and also you can use system function to run external programs as well.
And also if you wonder what's the difference:
PHP - exec() vs system() vs passthru()
I'm trying to take a generated html file and convert it to PDF on the fly with PHP.
It's going on my localhost and staying there so for the PDF conversion I'm using a Mac OSX utility, I guess you would call it.
The terminal command being:
/System/Library/Printers/Libraries/convert -f temporary.html -o destination/final.pdf
This works properly via terminal (produces a simple 20kb PDF file); however, when I run it inside PHP via passthru() the file (final.pdf) is created though it is a Zero KB file (corrupt).
The /destination folder is CHMOD 777, temporary.html is CHMOD 755.
Any help would be greatly appreciated.
Edit (Additional Detail):
Now in the error log, amongst the debug lines there is an error of "ERROR: xhtmltopdf (PID 13204) crashed on signal 6!"
I like to share what I do to generate PDF file on the fly. We use UNIX server to host.
I use tcpdf - a php library to convert HTML to PDF file. I use it in my projects and it works very well. TCPDF supports css, javascript, forms, images and lot more.
Website: http://www.tcpdf.org/
Demos: http://www.tcpdf.org/examples.php
When I need convert HTML in PDF I use this very nice software: http://www.princexml.com
You could have a look, it's free for personal use.
hey guys , im dealing with a script that it should compress and folder and make it ready in 3 versions :
7z
zip
tar.gz
surely i did found a way on how to make a zip file out of a folder in php by using a zip compression class
http://www.phpclasses.org/package/2322-PHP-Create-ZIP-file-archives-and-serve-for-download.html
but for 7z and tar.gz format no idea on how to do the compression
is there any way to make an 7z or tar.gz compressed file !?
specially 7z format
I suggest you install the relevant programs on the server, and call them from php via exec() to compress your files for you. Why bother rewriting the compression code when it's already been written?
Assuming Linux and having these (basic) tools already available:
exec("zip -r archive_name.zip directory_to_compress");
exec("tar -zcvf archive_name.tar.gz directory_to_compress");
For 7zip, you can check out this project on SourceForge.