Web - кодинг: PHP:


Работа с .gz и .zip архивами



  Источник:

Работа с .gz архивами:

<?php
$filename = tempnam ('/tmp', 'zlibtest').'.gz';
print "\\n\\n\\n

\\n";
$s = "Only a test, test, test, test, test, test, test!\\n";
// open file for writing with maximum compression
$zp = gzopen($filename, "w9");
// write string to file
gzwrite($zp, $s);
// close file
gzclose($zp);
// open file for reading
$zp = gzopen($filename, "r");
// read 3 char
print gzread($zp, 3);
// output until end of the file and close it.
gzpassthru($zp);
print "\\n";
// open file and print content (the 2nd time).
if (readgzfile($filename) != strlen($s)) {
echo "Error with zlib functions!";
}
unlink($filename);
print "
\\n\\n\\n";
?>

Работа с .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_entry, zip_entry_filesize($zip_entry));
echo "$buf\\n";

zip_entry_close($zip_entry);
}
echo "\\n";
}
zip_close($zip);
}
?>





При перепечатке любого материала с сайта, видимая ссылка на источник www.warayg.narod.ru и все имена, ссылки авторов обязательны.

© 2005