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.
Related
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;
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 setting up a script so that I can input a URL to a web page and the script will wget the file. Most of the files, however, will be in the *.rar format. Is there anyway I can pass the filename to the unrar command to unarchive the files downloaded via wget?
Many, many thanks in advance!
EDIT I thought about using PHP's explode() function to break up the URL by the slashes (/) but that seems a bit hack-y.
Rather than forking out to external programs to download and extract the file, you should consider using PHP's own cURL and RAR extensions. You can use the tmpfile() function to create a temporary file, use it as the value of the CURLOPT_FILE option to make cURL save the downloaded file there, and then open that file with the RAR functions to extract the contents.
Use basename()to get the filename.
#Wyzard gives the best answer. If there's a library that solves your problem, use it instead of forking an external process. It's safer and it's the clean solution. PHP's cURL and RAR are good, use them.
However, if you must use wget and unrar, then #rik gives a good answer. wget's -O filename option saves the file as filename, so you don't have to work it out. I would rather pipe wget's output directly to unrar though, using wget -q -O - http://www.example.com | unrar.
#Byron's answer is helpful, but you really should not need to use it here. It is, however, better than using explode() as your edit mentions.
wget -O filename URL && unrar filename
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.
I'm trying to write a script that allows an admin of a photo uploading system download all their photos at once.
Currently I am using
system('zip -r '.$_SERVER['DOCUMENT_ROOT'].'/zip.zip '.$_SERVER['DOCUMENT_ROOT'].'/images/photo-uploads';
to zip the files but this seems to echo names and locations all the files onto the page.
Is there anyway to get around this? If not what is the best way to zip files on server.
You might use exec('zip -r '.$_SERVER['DOCUMENT_ROOT'].'/zip.zip '.$_SERVER['DOCUMENT_ROOT'].'/images/photo-uploads'); instead.
You can use ZipArchive extension instead (if you are allowed to) of calling system zip like that, because it makes your code non-portable.
You can also use output buffering:
ob_start();
system('zip -r '.$_SERVER['DOCUMENT_ROOT'].'/zip.zip '.$_SERVER['DOCUMENT_ROOT'].'/images/photo-uploads';
ob_end_clean();
This will stop any output from being shown from the system command.