锟斤拷锟斤拷

Example #1 锟斤拷锟斤拷一锟斤拷 Zip 锟介档

<?php

$zip 
= new ZipArchive();
$filename "./test112.zip";

if (
$zip->open($filenameZIPARCHIVE::CREATE)!==TRUE) {
    exit(
"cannot open <$filename>\n");
}

$zip->addFromString("testfilephp.txt" time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir "/too.php","/testfromfile.php");
echo 
"numfiles: " $zip->numFiles "\n";
echo 
"status:" $zip->status "\n";
$zip->close();
?>

Example #2 锟斤拷锟斤拷牡锟较革拷诤锟斤拷斜锟�

<?php
$za 
= new ZipArchive();

$za->open('test_with_comment.zip');
print_r($za);
var_dump($za);
echo 
"numFiles: " $za->numFiles "\n";
echo 
"status: " $za->status  "\n";
echo 
"statusSys: " $za->statusSys "\n";
echo 
"filename: " $za->filename "\n";
echo 
"comment: " $za->comment "\n";

for (
$i=0$i<$za->numFiles;$i++) {
    echo 
"index: $i\n";
    
print_r($za->statIndex($i));
}
echo 
"numFile:" $za->numFiles "\n";
?>

Example #3 Zip 锟斤拷锟斤拷装锟斤拷锟斤拷取一锟斤拷 OpenOffice 锟侥硷拷锟斤拷元锟斤拷息

<?php
$reader 
= new XMLReader();

$reader->open('zip://' dirname(__FILE__) . '/test.odt#meta.xml');
$odt_meta = array();
while (
$reader->read()) {
    if (
$reader->nodeType == XMLREADER::ELEMENT) {
        
$elm $reader->name;
    } else {
        if (
$reader->nodeType == XMLREADER::END_ELEMENT && $reader->name == 'office:meta') {
            break;
        }
        if (!
trim($reader->value)) {
            continue;
        }
        
$odt_meta[$elm] = $reader->value;
    }
}
print_r($odt_meta);
?>

锟斤拷锟斤拷使锟斤拷锟剿旧碉拷 API锟斤拷PHP 4锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷 ZIP 锟侥硷拷锟介档锟斤拷锟斤拷取锟介档锟斤拷锟矫匡拷锟斤拷募锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟捷★拷锟斤拷锟斤拷锟矫碉拷锟斤拷 test2.zip 锟侥碉拷锟斤拷 ZZIPlib 源锟街诧拷锟斤拷锟斤拷锟斤拷牡锟斤拷械锟揭伙拷锟斤拷锟�

Example #4 Zip 使锟矫凤拷锟斤拷

<?php

$zip 
zip_open("/tmp/test2.zip");

if (
$zip) {
    while (
$zip_entry zip_read($zip)) {
        echo 
"Name:               " zip_entry_name($zip_entry) . "\n";
        echo 
"Actual Filesize:    " zip_entry_filesize($zip_entry) . "\n";
        echo 
"Compressed Size:    " zip_entry_compressedsize($zip_entry) . "\n";
        echo 
"Compression Method: " zip_entry_compressionmethod($zip_entry) . "\n";

        if (
zip_entry_open($zip$zip_entry"r")) {
            echo 
"File Contents:\n";
            
$buf zip_entry_read($zip_entryzip_entry_filesize($zip_entry));
            echo 
"$buf\n";

            
zip_entry_close($zip_entry);
        }
        echo 
"\n";

    }

    
zip_close($zip);

}
?>