Login   Register  
PHP Classes
elePHPant
Icontem

File: Zip.Example1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Asbjorn Grandt  >  Zip  >  Zip.Example1.php  >  Download  
File: Zip.Example1.php
Role: Example script
Content type: text/plain
Description: Example file for generating a download file.
Class: Zip
Create archives of compressed files in ZIP format
Author: By
Last change: * Added example for the addDirectoryContent function added in Zip.php version 1.22.
Date: 2011-03-12 02:57
Size: 1,259 bytes
 

Contents

Class file image Download
<?php
// Example. Zip all .html files in the current directory and send the file for Download.
// Also adds a static text "Hello World!" to the file Hello.txt
$fileDir './';
ob_start(); // This is only to show that ob_start can be called, however the buffer must be empty when sending.

include_once("Zip.php");
$fileTime date("D, d M Y H:i:s T");

$zip = new Zip();
$zip->setComment("Example Zip file.\nCreated on " date('l jS \of F Y h:i:s A'));
$zip->addFile("Hello World!""hello.txt");

@
$handle opendir($fileDir);
if (
$handle) {
    
/* This is the correct way to loop over the directory. */
    
while (false !== ($file readdir($handle))) {
        if (
strpos($file".html") !== false) {
            
$pathData pathinfo($fileDir $file);
            
$fileName $pathData['filename'];

            
$zip->addFile(file_get_contents($fileDir $file), $filefilectime($fileDir $file));
        }
    }
}

// Add a directory, forst recursively, then the same directory, but without recursion.
// Naturally this requires you to change the path to ../test to point to a directory of your own.
$zip->addDirectoryContent("../test""recursiveDir/test");
$zip->addDirectoryContent("../test""recursiveDir/testFlat"FALSE);

$zip->sendZip("ZipExample1.zip");
?>