Home > php教程 > php手册 > body text

php操作(删除,提取,增加)zip文件方法详解

WBOY
Release: 2016-06-06 20:06:55
Original
1129 people have browsed it

本文给大家分享的是php操作zip文件的方法示例,包括了从zip压缩文件中提取文件、从一个zip压缩文件中删除文件、添加一个文件到zip压缩文件中,推荐给大家,有需

php读取zip文件(删除文件,提取文件,增加文件)实例

从zip压缩文件中提取文件

复制代码 代码如下:


/*
php 从zip压缩文件中提取文件
*/
$zip = new ZipArchive;
if ($zip->open('jQuery五屏上下滚动焦点图代码.zip') === TRUE) {//中文文件名要使用ANSI编码的文件格式
    $zip->extractTo('foldername');//提取全部文件
    //$zip->extractTo('/my/destination/dir/', array('pear_item.gif', 'testfromfile.php'));//提取部分文件
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

从一个zip压缩文件中删除文件

复制代码 代码如下:


/*
php 从一个zip压缩文件中删除文件
*/
$zip = new ZipArchive;
if ($zip->open('ajaxupload.zip') === TRUE) {
    $zip->deleteName('file.txt');//删除文件
    $zip->deleteName('testDir/');//删除文件夹
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

添加一个文件到zip压缩文件中

复制代码 代码如下:


/*
php 添加一个文件到zip压缩文件中
*/
$zip = new ZipArchive;
if ($zip->open('ajaxupload.zip') === TRUE) {//ajaxupload.zip 是已经存在的zip文件,注意中文文件名要注意编码问题
    $zip->addFile('33.xml');//添加新的文件
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

以上就是本文所述的全部内容了,希望对大家理解php操作zip文件能有所帮助。

Related labels:
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 Recommendations
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!