PHP Classes

A little change in code...

Recommend this page to a friend!

      Create ZIP File  >  All threads  >  A little change in code...  >  (Un) Subscribe thread alerts  
Subject:A little change in code...
Summary:A little change in code...
Author:Marcus Hjortsberg
Date:2011-08-10 14:46:46

  1. A little change in code...   Reply   Report abuse  
Picture of Marcus Hjortsberg Marcus Hjortsberg - 2011-08-10 14:46:46
I have made a little change to the code so that the files is saved directly in the zip file without the folder hierarchy.

I have also put a little extra code so that some file extensions can be excluded.

But I think it can be problems if the folder you want ti zip contains sub folders, but this is just a thought...not tested...I only have the need to zip folders without sub folders at the moment...

The code...(replace the zipDirectory function)

public function zipDirectory($dirName, $outputDir) {
if (!is_dir($dirName)){
trigger_error("CreateZipFile FATAL ERROR: Could not locate the specified directory $dirName", E_USER_ERROR);
for ($i=0;$i<$count;$i++){

$parts = explode(".", $fileToZip);
if (is_array($parts) && count($parts) > 1)
$extension = end($parts);
if ($extension == "zip" OR $extension == "ZIP")
$parts2 = explode("/", $fileToZip);
$file = end($parts2);