Creating ZIP Files in PHP


Create and manage ZIP files to compress or decompress data.

Source Code

$zip = new ZipArchive();
if ($zip->open('myFiles.zip', ZipArchive::CREATE) === TRUE) {
    $zip->addFromString('test.txt', 'file content here');
    $zip->addFile('data.txt', 'newname.txt');
    $zip->close();
    echo "ZIP file created successfully.";
} else {
    echo "Failed to create ZIP file.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments