Unzipping a directory within a zip file
Posted: Thu Jun 12, 2008 1:21 pm
So I have a zip file that has the following directory structure
Fit Y by X - Contextual.zip
>[dir] _rels
>[dir] word
>[dir] media <-- this is inside the word folder
>[dir] docProp
So basically what I'm trying to extract is all the contents inside the word/media/ folder.
I'm using the example provided in the php.net http://us2.php.net/manual/en/function.z ... ractto.php
The example appears to be good for specific files inside the main directory as soon as you open up the zip. But it doesn't specify how to extract folders, files within folders, or folders within folders.
I'm not sure what goes inside the second parameter
I've tried all sorts of permutations such as:
array('word\media\.')
array("word\media\")
array('word\media\')
array("word/media/.")
array('word/media/.')
array("word/media/")
array('word/media/')
as well as all of those without the array functions and none seem to work. Any suggestions?
Fit Y by X - Contextual.zip
>[dir] _rels
>[dir] word
>[dir] media <-- this is inside the word folder
>[dir] docProp
So basically what I'm trying to extract is all the contents inside the word/media/ folder.
I'm using the example provided in the php.net http://us2.php.net/manual/en/function.z ... ractto.php
The example appears to be good for specific files inside the main directory as soon as you open up the zip. But it doesn't specify how to extract folders, files within folders, or folders within folders.
Code: Select all
<?php
$zip = new ZipArchive;
$res = $zip->open('Fit Y by X - Contextual.docx');
if ($res === TRUE) {
$zip->extractTo('extract/', array("word\media\.")); [color=#40FF00]//<---- not sure what goes in the second parameter[/color]
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
I've tried all sorts of permutations such as:
array('word\media\.')
array("word\media\")
array('word\media\')
array("word/media/.")
array('word/media/.')
array("word/media/")
array('word/media/')
as well as all of those without the array functions and none seem to work. Any suggestions?