本文给大家分享的是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文件能有所帮助。
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor