Home > Backend Development > PHP Problem > How to use php ziparchive

How to use php ziparchive

藏色散人
Release: 2023-03-08 16:50:01
Original
1924 people have browsed it

php ziparchive usage: first open the test.zip file; then add the image.txt file to test.zip; finally add the image.txt file to the zip file through "$zip->addFromString(...)" Just append content to the test.txt file.

How to use php ziparchive

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php experience using ZipArchive to compress files

$zip=new ZipArchive;
if($zip->open('test.zip',ZipArchive::CREATE)===TRUE){
$zip->addFile('image.txt');//假设在当前路径下加入的文件名是image.txt
$zip->close();
}
Copy after login

Function: Open the test.zip file by default, create a test.zip file if it does not exist, and then add the image.txt file to test.zip.

Note: If image.txt is not added to the created zip file, the created compressed package will not be visible.

$zip->addFromString('test.txt','file content goes here');
Copy after login

Function: Append content to the test.txt file in the zip file

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to use php ziparchive. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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