addFromString(...)" Can."/> addFromString(...)" Can.">

Home  >  Article  >  Backend Development  >  How to use php ziparchive

How to use php ziparchive

藏色散人
藏色散人Original
2021-03-12 09:05:301872browse

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();
}

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');

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!

Statement:
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