compressing a folder into different formats in php - php

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.

Related

Extract ZIP in php, overwriting everything

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.

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.
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.

Simple solution to extract PDF.zip using PHP

I have a rather large zip file (I used 7zip to compress the files) and I must now extract the files that are on the server. I tried using CPANEL File Manager but the zip file is too big.
Any ideas on how I can extract this zip file?
I do not have SHELL ACCESS and would prefer to use a software tool, if there is one out there.
Can you try, maybe this works. You can also use exec function
<?php
$salida = shell_exec('unzip you.zip');
echo $salida;

Creating selfextracting zips in php on the fly

I'm working on a php script packaging some files (a setup.exe and a licence.txt which is created direct in php for the user). We don't want that the user has to unzip it and start setup.exe.
On the computer we solved that by using selfextracting zips with:
zip is called setup.exe
zip has icon of the application
destination of extraction is temporary folder
extracting process is hidden
So if the user click on setup.exe he don't know that this setup.exe is a zip at the end.
But is that also possible on the server in the php script?
i tried the normal ziparchive object and pclzip and i can create the zip with these libraries. But i cannot change the parameters above...
Can anyone tell me if there's a solution for this?
Use PHP:exec to run an external application that compress and compile your exec file, with your stuff inside as you need.
PHP don't have built-in function to compress and compile and executable file.

Extracting self-extracting exe archive via php

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()

Categories