PHP Classes

File: exampleScript.php

Recommend this page to a friend!
  Classes of Er. Rochak Chauhan   Create ZIP File   exampleScript.php   Download  
File: exampleScript.php
Role: Example script
Content type: text/plain
Description: Example file
Class: Create ZIP File
Create ZIP file archives and serve for download
Author: By
Last change: Added feature to unzip all the files and directories inside a directory.
PS: The max size of this zip file can be less that the "memory_limit" mentioned in the php.ini.
Date: 14 years ago
Size: 926 bytes
 

Contents

Class file image Download
<?php
$fileToZip
="License.txt";
$fileToZip1="CreateZipFileMac.inc.php";
$fileToZip2="CreateZipFile.inc.php";

$directoryToZip="./"; // This will zip all the file(s) in this present working directory

$outputDir="/"; //Replace "/" with the name of the desired output directory.
$zipName="test.zip";

include_once(
"CreateZipFile.inc.php");
$createZipFile=new CreateZipFile;

/*
// Code to Zip a single file
$createZipFile->addDirectory($outputDir);
$fileContents=file_get_contents($fileToZip);
$createZipFile->addFile($fileContents, $outputDir.$fileToZip);
*/

//Code toZip a directory and all its files/subdirectories
$createZipFile->zipDirectory($directoryToZip,$outputDir);

$rand=md5(microtime().rand(0,999999));
$zipName=$rand."_".$zipName;
$fd=fopen($zipName, "wb");
$out=fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
$createZipFile->forceDownload($zipName);
@
unlink($zipName);
?>