PHP Classes

File: example1.php

Recommend this page to a friend!
  Classes of Joshua Townsend   Zip File   example1.php   Download  
File: example1.php
Role: Example script
Content type: text/plain
Description: Example of using class to zip a file.
Class: Zip File
Create and extract ZIP archives in purely in PHP
Author: By
Last change: Renamed to example1.php and updated to reflect function name changes
Date: 17 years ago
Size: 565 bytes
 

Contents

Class file image Download
<?php
require "zip.class.php"; // Get the zipfile class
$zipfile = new zipfile; // Create an object
$zipfile->create_dir("."); // Add a subdirectory - must be done. If a subdirectory is not wanted, just simply add one named "." as shown here
$zipfile->create_file(file_get_contents(__FILE__), "zip.txt"); // Add the data of the file that is wanted, and the full path to it in the zip.

// Allow user to download file
header("Content-type: application/zip");
header("Content-disposition: attachment;filename=\"zip.zip\"");
echo
$zipfile->zipped_file();
?>