How to rename a folder using ZipArchive?
is th开发者_如何转开发ere any solution to rename a folder inside zipfile before unzipping ?
$zip = new ZipArchive();
$result=$zip->renameName($acfoldername , $renameFolder );
Function renameName seems only to rename files and not folders
$zip->renameName($acfoldername , $renameFolder );
OR is there any solution in Zend Framework for zip file management?
rename directory inside zipfile using ZipArchive :-)
$tmpfile = "myzip.zip";
copy( "template.zip", $tmpfile );
$zip = new ZipArchive;
$res = $zip->open( $tmpfile, ZipArchive::CREATE );
if ($res === TRUE) {
$index = "<html>content</html>";
$zip->addFromString('dirname/index.html', $index);
$zip->addFile("mp3/sample.mp3", 'dirname/audio/myAudioFile.mp3');
// rename directory "dirname"
$name="newDirectoryName";
$i=0;
while($item_name = $zip->getNameIndex($i)){
$zip->renameIndex( $i, str_replace( "dirname", $name, $item_name ) );
$i++;
}
$zip->close();
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$name.'.zip"');
readfile($tmpfile);
unlink($tmpfile);
}
Sorry , but there is no class in the ZF that able to rename folder inside of the ZIP file
but again there is nothing impossible you can use the same ZipArchive to extract the file somewhere and then using the function Glob
or SPL Directory Iterator
"
to locate your wanted folder using rename
and the last step is to zip your folder again using the same ZipArchive
example of creating zip file : http://davidwalsh.name/create-zip-php
精彩评论