Unzip file using PHP
A few days ago i was looking for a script witch one will help me to unzip a file using PHP . There is 2 different ways to do it.One just execute a commend to unzip the file in the shell using PHP and another one is using library functions .Then i found this script from phpxperts.
// create object
$zip = new ZipArchive() ;
// open archive
if ($zip->open(‘archive. zip’) !== TRUE) {
die (‘Could not open archive’);
}
// extract contents to destination directory
$zip->extractTo(‘/ tmp/extracted/ ‘);
// close archive
// print success message
$zip->close();
echo ‘Archive extracted to directory’;
thanx..
Thanks to share this stuff
I think its helpful.
Simply Nice. Thnx to find out this.
Thanks a lot man, this works just fine with zipped images is great!!
yeah nice but wheres the rest!
Aint there meant to be a class lol
Usefull.
thanxx
Thanks for simple script.
Hi,
I am using the above code to unzip a zip file. But it shows that Class ‘ZipArchive’ not found.
Please help me.
Thanks, Very nice, Got after a long search. Thanks
It looks like you need to have php compiled with this library (found here)included. I’d guess that some hosts do this by default, but some (mine included) don’t.
I’ve found it’s usually easier to just use exec() and have php do it from the command line.
Hi,
Thank you so much for such a simple script. This is really helpful.
Hi,
It’s Usefull, thanks. But I am using the above code to unzip a zip file on linux server can’t effect. Please help me.
Hi…
anyone knows how to access a zip file from a server where path to server is given as a http url……i have tride to give path in zip->open …but doesn’t wrks..
i hope somedbody finds me soln..:)..
Hi….
atlast soltn found…just use copy keyword…..rest done…:)
Many thanks!
help
if php does not have built in zip support using system call to the unzip binarystatus ?
Nice script, but if worked :(. it shows that Class βZipArchiveβ not found.
I am using Linux server, and above script didn’t work at all with my case.
I just want to share a working script of same functionality at : http://www.joretha.com/index.php/other/technical-articles/php-linux-unzip.html
Hope it will help.
Thanks a lot…………………..
π
I am using this code. It’s realy greate.
Thanks a lot brother.
π
thank u too for ur comment π
Looks easy! =D
But just 1 question…
$zip->extractTo(β/ tmp/extracted/ β);
Can this be: $zip->extractTo(β/public_html/myfolder/ β);
instead?
Will they overwrite existing files as well?
Regards
Avatar The Last Airbender
thanks… itΒ΄s very simple…