March 31, 201313 yr Hi All, i am trying to unzip the contents of a zipped folder into the root of the site, i can only make it work by extracting the contents and creating a directory with the same name of the zipped folder, so i have a directory called zip when i run the below php <?php $zip = new ZipArchive; if ($zip->open('zip.zip') === TRUE) { $zip->extractTo('unzip.dev'); $zip->close(); echo 'ok'; } else { echo 'failed'; } ?> what i woluld like is the contents of zip.zip to be in the unzip.dev directory any ideas? Thanks
March 31, 201313 yr Author Solved <?php $path = 'zip.zip'; $zip = new ZipArchive; if ($zip->open($path) === true) { for($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); $fileinfo = pathinfo($filename); copy("zip://".$path."#".$filename, "".$fileinfo['basename']); } $zip->close(); } ?>
Create an account or sign in to comment