Make folder zip with php

Watch latest movie trailer on Bma Trailers

This code will zip the folder not single file but the whole folder…. You need to download the class mentioned below

Download this class from here 
http://www.phpclasses.org/package/2322-PHP-Create-ZIP-file-archives-and-serve-for-download.html



<?php
$date = date("d-m-y");

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

$outputDir="/"; //Replace "/" with the name of the desired output directory.
$zipName="File name - ".$date.".zip"; //Save file with specified name 

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

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

$fd=fopen($zipName, "wb");
$out=fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
$createZipFile->forceDownload($zipName);
@unlink($zipName);
?>

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s