服务器端解压缩zip的脚本
程序员文章站
2022-12-04 12:06:20
复制代码 代码如下:
复制代码 代码如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>文件解压缩管理</title>
</head>
<body>
<?php
// in php versions earlier than 4.1.0, $http_post_files should be used instead
// of $_files.
if (isset($_post["submit"])) {
echo "filename: " . $_post['unpackfile'] . "<br />\n";
echo "unpackpath: " . $_post['unpackpath'] . "<br />\n";
$zip = zip_open($_post['unpackfile']);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
echo "name: " . zip_entry_name($zip_entry) . "<br />\n";
echo "actual filesize: " . zip_entry_filesize($zip_entry) . "<br />\n";
echo "compressed size: " . zip_entry_compressedsize($zip_entry) . "<br />\n";
echo "compression method: " . zip_entry_compressionmethod($zip_entry) . "<br />\n";
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); // file content
echo "step 1 successful!<br />\n";
if(zip_entry_filesize($zip_entry)!=0) {
$fp = fopen($_post['unpackpath']."/".zip_entry_name($zip_entry), 'wb');
fwrite($fp, $buf);
fclose($fp);
zip_entry_close($zip_entry);
echo "unpack successful!<br />\n";
} else {
mkdir($_post['unpackpath']."/".zip_entry_name($zip_entry), 0777);
echo "mkdir successful!<br />\n";
}
}
echo "<br><br>\n\n";
}
zip_close($zip);
}
?>
</body>
</html>
<?php
exit();
}
?>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="<?=$_server['php_self']?>">
待解压文件<input type="text" name="unpackfile" />
解压缩路径<input type="text" name="unpackpath" />
<input type="submit" name="submit" value="解压" />
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>文件解压缩管理</title>
</head>
<body>
<?php
// in php versions earlier than 4.1.0, $http_post_files should be used instead
// of $_files.
if (isset($_post["submit"])) {
echo "filename: " . $_post['unpackfile'] . "<br />\n";
echo "unpackpath: " . $_post['unpackpath'] . "<br />\n";
$zip = zip_open($_post['unpackfile']);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
echo "name: " . zip_entry_name($zip_entry) . "<br />\n";
echo "actual filesize: " . zip_entry_filesize($zip_entry) . "<br />\n";
echo "compressed size: " . zip_entry_compressedsize($zip_entry) . "<br />\n";
echo "compression method: " . zip_entry_compressionmethod($zip_entry) . "<br />\n";
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); // file content
echo "step 1 successful!<br />\n";
if(zip_entry_filesize($zip_entry)!=0) {
$fp = fopen($_post['unpackpath']."/".zip_entry_name($zip_entry), 'wb');
fwrite($fp, $buf);
fclose($fp);
zip_entry_close($zip_entry);
echo "unpack successful!<br />\n";
} else {
mkdir($_post['unpackpath']."/".zip_entry_name($zip_entry), 0777);
echo "mkdir successful!<br />\n";
}
}
echo "<br><br>\n\n";
}
zip_close($zip);
}
?>
</body>
</html>
<?php
exit();
}
?>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="<?=$_server['php_self']?>">
待解压文件<input type="text" name="unpackfile" />
解压缩路径<input type="text" name="unpackpath" />
<input type="submit" name="submit" value="解压" />
</form>
</body>
</html>
上一篇: 剖析 PHP 中的输出缓冲