PHP怎么解压ZIP文件
2个回答
展开全部
?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);
}
?>
展开全部
rar文件解压php没有直接支持的,不过可以通过下载将非线程安全的dll然后扔到php的ext目录下,之后按照下面的步骤操作即可。
打开php.ini.
加一行 extension=php_rar.dll
重启web服务器 和php
复制代码
代码如下:
public function _unzip($fileName,$extractTO){
$fileName = iconv('utf-8','gb2312',"upload/zip/8月.rar");
// echo $fileName . '</br>';
$extractTo = "upload/zip/TEST/";
$rar_file = rar_open($fileName) or die('could not open rar');
$list = rar_list($rar_file) or die('could not get list');
// print_r($list);
foreach($list as $file) {
$pattern = '/\".*\"/';
preg_match($pattern, $file, $matches, PREG_OFFSET_CAPTURE);
$pathStr=$matches[0][0];
$pathStr=str_replace("\"",'',$pathStr);
// print_r($pathStr);
$entry = rar_entry_get($rar_file, $pathStr) or die('</br>entry not found');
$entry->extract($extractTo); // extract to the current dir
}
rar_close($rar_file);
}
打开php.ini.
加一行 extension=php_rar.dll
重启web服务器 和php
复制代码
代码如下:
public function _unzip($fileName,$extractTO){
$fileName = iconv('utf-8','gb2312',"upload/zip/8月.rar");
// echo $fileName . '</br>';
$extractTo = "upload/zip/TEST/";
$rar_file = rar_open($fileName) or die('could not open rar');
$list = rar_list($rar_file) or die('could not get list');
// print_r($list);
foreach($list as $file) {
$pattern = '/\".*\"/';
preg_match($pattern, $file, $matches, PREG_OFFSET_CAPTURE);
$pathStr=$matches[0][0];
$pathStr=str_replace("\"",'',$pathStr);
// print_r($pathStr);
$entry = rar_entry_get($rar_file, $pathStr) or die('</br>entry not found');
$entry->extract($extractTo); // extract to the current dir
}
rar_close($rar_file);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询