Login   Register  
PHP Classes
elePHPant
Icontem

How can I zip specific folder ?

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Zip  >  All threads  >  How can I zip specific folder ?  >  (Un) Subscribe thread alerts  
Subject:How can I zip specific folder ?
Summary:Modified the script to get specific folder contents
Messages:3
Author:Sumith Harshan
Date:2012-10-16 15:54:43
Update:2012-10-16 18:23:48
 

  1. How can I zip specific folder ?   Reply   Report abuse  
Picture of Sumith Harshan
Sumith Harshan
2012-10-16 15:54:43
I modified the script as follows.

ob_start();
include_once("Zip.php");
$zip = new Zip();

$fileDirectory = 'Folder_name_to_zip/';


foreach (new DirectoryIterator($fileDirectory) as $file) {
if($file->isDot()) continue;
$zip->addFile( file_get_contents($fileDirectory.$file->getFilename(),$fileDirectory),$file->getFilename() );
}

$zip->sendZip("ZipFile.zip");

More info: http://faq.pctrickers.com/php-creating-zip-files/

  2. Re: How can I zip specific folder ?   Reply   Report abuse  
Picture of Asbjorn Grandt
Asbjorn Grandt
2012-10-16 18:23:48 - In reply to message 1 from Sumith Harshan
First, you should avoid ob_start()

Next, have you tried the addDirectoryContent function in Zip?

$zip->addDirectoryContent($realPath, $zipPath, $recursive, $followSymlinks, &$addedFiles);

Only the first two arguments are required.

So from your example I'd say the command is:
$zip->addDirectoryContent($fileDirectory, "");


Arguments:

String $realPath Path on the file system.

String $zipPath Filepath and name to be used in the archive.

bool $recursive Add content recursively, default is TRUE.

bool $followSymlinks Follow and add symbolic links, if they are accessible, default is TRUE.

array &$addedFiles Reference to the added files, this is used to prevent duplicates, default is an empty array.
If you start the function by parsing an array, the array will be populated with the realPath and zipPath kay/value pairs added to the archive by the function.

  3. Re: How can I zip specific folder ?   Reply   Report abuse  
Picture of dang thi ngoc
dang thi ngoc
2014-11-12 11:08:39 - In reply to message 2 from Asbjorn Grandt
Hi Asbjorn Grandt,
i can zip Directory as your way.
But i doesn't support utf8 file names as $zip->addFile.
i need to zip folder include some Chinese File.
could you help me?
Thanks.