<?php
//////////////////////////////////////////////////////////////////////////
//
// Zips the entire dir (except itself) and send to the browser
// Scripting (c) 2003 Matthijs van de Water
// NEEDS COMPATIBLE PHP ZIP CLASS - SEE PHPMYADMIN
//
//////////////////////////////////////////////////////////////////////////

// Current dir
$dir '.';

// Use the name of the current directory as the zipfile name
$tmp explode('/'realpath($dir));
$zipfilename $tmp[count($tmp) - 1];
unset(
$tmp);

// Require ZIP functions class
require('../classes/zip.php');

// Send appropriate header
function sendheader ($filename
{
    
header('Content-Type: application/x-zip');
    if (
strstr($HTTP_USER_AGENT'MSIE')) 
    {
         
header('Content-Disposition: inline; filename="' $filename '.zip"');
         
header('Expires: 0');
         
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         
header('Pragma: public');
    }
    else 
    {
         
header('Content-Disposition: attachment; filename="' $filename '.zip"');
         
header('Expires: 0');
         
header('Pragma: no-cache');
    }
}

// Create new zipfile
$zipfile = new zipfile;

// Process dir, check each file for inclusion
$dir_handle opendir($dir);
while ((
$filename readdir($dir_handle)) !== false
{
    
// Exclude this script from inclusion in the ZIP file
    
if ($filename != basename($PHP_SELF) && is_file($filename))
    {

        
// Get file info and contents
        
$ftime filectime($filename);
        
$fsize filesize($filename);
        
$fp fopen($filename'r');
        
$fcontents fread($fp$fsize);
        
fclose($fp);

        
// Put file in zip archive
        
$zipfile->addFile($fcontents$filename$ftime);
    }
}

// Build appropriate header
sendheader($zipfilename);
header("Content-Length: " strlen($zipfile->file()));

// Output zipfile to browser
echo $zipfile->file();

?>