Friday 11 July 2014

How to zip all directory/folders in root folder in php

Before Starting...

Know about file location

My File exist in C:\xampp\htdocs\ftp\index.php 
In ftp directory we have  6 more directories and  names are
  • John
  • Jill
  • Cafe
  • Monit
  • Rifle
  • Kim.
3. We Want to zip all the directory at one time without enter the  individual directory name.

index.php 
<?php
$ar = array();
$directory = "./";
$files = glob($directory . "*", GLOB_ONLYDIR );
foreach($files as $file)
{
   $ar[] =  basename($file);
}
$a =count($ar); 
for($i=0;$i<$a;$i++)
{
$filename= $ar[$i];
$source_path= $filename;
$the_folder =$source_path;
$zip_file_name = $the_folder.".zip";
$za = new FlxZipArchive;
$res = $za->open($zip_file_name, ZipArchive::CREATE);
if($res === TRUE) 
{
 $za->addDir($the_folder, basename($the_folder));
 $za->close();
}
else  { echo 'Could not create a zip archive';}
} ?>


No comments:

Post a Comment