<?php
$zip = new ZipArchive();
if ($zip->open('test.zip') === TRUE) {
for ($idx=0 ; $s = $zip->statIndex($idx) ; $idx++) {
if ($zip->extractTo('.', $s['name'])) {
if ($zip->getExternalAttributesIndex($idx, $opsys, $attr)
&& $opsys==ZipArchive::OPSYS_UNIX) {
chmod($s['name'], ($attr >> 16) & 0777);
}
}
}
$zip->close();
echo "Ok\n";
} else {
echo "KO\n";
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(1)
<?php
$zip = new ZipArchive;
$res = $zip->open('test1.zip');
if ($res === TRUE) {
var_dump($zip->getCommentName('test/entry1.txt'));
} else {
echo 'failed, code:' . $res;
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(5)
<?php
$zip = new ZipArchive;
$res = $zip->open('test1.zip');
if ($res === TRUE) {
var_dump($zip->getCommentIndex(1));
} else {
echo 'failed, code:' . $res;
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(2)
<?php
$zip = new ZipArchive;
$res = $zip->open('test_with_comment.zip');
if ($res === TRUE) {
var_dump($zip->getArchiveComment());
/* Or using the archive property */
var_dump($zip->comment);
} else {
echo 'failed, code:' . $res;
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(5)
例:解壓縮全部檔案至一目錄
<?php
$zip = new ZipArchive;
if ($zip->open('/raid/vhost/treetech.tw/www/test/test.zip') === TRUE) {
$zip->extractTo('/raid/vhost/treetech.tw/www/test/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(822)
例1:使用名稱從歸檔中刪除文件和目錄
<?php
$zip = new ZipArchive;
if ($zip->open('test1.zip') === TRUE) {
$zip->deleteName('testfromfile.php');
$zip->deleteName('testDir/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(7)
例1 使用其索引從歸檔中刪除文件
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->deleteIndex(2);
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(9)
<?php
$zip = new ZipArchive();
$ret = $zip->open('application.zip', ZipArchive::OVERWRITE);
if ($ret !== TRUE) {
printf('Failed with code %d', $ret);
} else {
$directory = realpath('.');
$options = array('add_path' => 'sources/', 'remove_path' => $directory);
$zip->addPattern('/\.(?:php|txt)$/', $directory, $options);
$zip->close();
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(29)
例:從當前目錄添加所有php腳本和文本文件
<?php
$zip = new ZipArchive();
$ret = $zip->open('application.zip', ZipArchive::OVERWRITE);
if ($ret !== TRUE) {
printf('Failed with code %d', $ret);
} else {
$directory = realpath('.');
$options = array('add_path' => 'sources/', 'remove_path' => $directory);
$zip->addPattern('/\.(?:php|txt)$/', $directory, $options);
$zip->close();
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(10)
<?php
$zip = new ZipArchive();
$ret = $zip->open('application.zip', ZipArchive::OVERWRITE);
if ($ret !== TRUE) {
printf('Failed with code %d', $ret);
} else {
$options = array('add_path' => 'sources/', 'remove_all_path' => TRUE);
$zip->addGlob('*.{php,txt}', GLOB_BRACE, $options);
$zip->close();
}
?>
stockwfj3 發表在 痞客邦 留言(0) 人氣(93)