How to decompress files in php Examples of how to decompress zip files in php

WBOY
Release: 2016-07-25 08:57:28
Original
741 people have browsed it
本文介绍下,用php解压zip格式文件的方法,介绍一个实用的小例子,有需要的朋友参考下。

以下是一个php解压zip文件的例子,可以将要上传的文件上传到服务器并解压。 代码:

<?php
/**
* php 解压文件
* edit by bbs.it-home.org
*/
header("Content-type: text/html;charset=utf-8");
error_reporting(E_ALL);
set_time_limit(0);
$zip_filename = "Test.zip";
$zip_filename = array_key_exists('zip', $_GET) && $_GET['zip'] ? $_GET['zip'] : $zip_filename;
$zip_filepath = str_replace('\\', '/', dirname(__FILE__)) . '/' . $zip_filename;
if(!is_file($zip_filepath))
{
    die("文件".$zip_filepath."不存在!");
}
$zip = new ZipArchive();
$rs = $zip->open($zip_filepath);
if($rs !== TRUE)
{
    die("解压失败!Error Code:". $rs);
}
$zip->extractTo("./");
$zip->close();
echo $zip_filename."解压成功!";
?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!