<?php
$path = 'zipfile.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, "/your/new/destination/".$fileinfo['basename']);
}
$zip->close();
}
// Extract only $filename
$filename = 'readme.txt';
$path = 'zipfile.zip';
$zip = new ZipArchive;
if ($zip->open($path) === true) {
for($i = 0; $i < $zip->numFiles; $i++) {
$fname = $zip->getNameIndex($i);
$fileinfo = pathinfo($fname);
if(
$fileinfo == $filename
){
copy("zip://".$path."#".$filename, "/sample_dir/".$fileinfo['basename']);
}
}
$zip->close();
}
?>
0 comments:
Post a Comment