Trying to Use PHP's Zip Archive - Extract To Doesn't Seem to be Working -
would appreciate on this. i've been trying write php script unzips zip file has been created using php's in-built zip archive extension.
the zipping-up process has been straight forward i'm trying unzip particular folder , doesn't seem working. thing create folder i've asked extract to. no files appear in folder.
i've had no error messages.
thanks in advance. here's code:
<?php $root = str_replace('public_html', '', $_server["document_root"]); $path = $root.'scripts.zip'; $zip = new ziparchive; $zipped = $zip->open($path, ziparchive::create | ziparchive::overwrite); $folder = $root.'public_html/scripts/'; if ($zipped) { $extract = $zip->extractto($folder); if ($extract){ echo 'zip file extracted'; } $zip->close(); } ?>
i modify code 1 below.
doing creating new zip file, not extracting old one. ziparchive::create
instructs code create zip, ziparchive::overwrite
tells overwrite existing files in zip.
so not extracting zip. code below should work
<?php $root = str_replace('public_html', '', $_server["document_root"]); $path = $root.'scripts.zip'; $zip = new ziparchive; $zipped = $zip->open($path); /*i have removed ::create & ::overwrite methods*/ $folder = $root.'public_html/scripts/'; if ($zipped) { $extract = $zip->extractto($folder); if ($extract){ echo 'zip file extracted'; } $zip->close(); } ?>
hope helps
Comments
Post a Comment