I use the following for zipping
//http://ninad.pundaliks.in/blog/2011/05/recursively-zip-a-directory-with-php/
class FlxZipArchive extends ZipArchive {
public function addDir($location, $name) {
$this->addEmptyDir($name);
$this->addDirDo($location, $name);
} // EO addDir
private function addDirDo($location, $name) {
$name .= '/';
$location .= '/';
// Read all Files in Dir
$dir = opendir ($location);
while ($file = readdir($dir))
{
if ($file == '.' || $file == '..') continue;
// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
$do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
$this->$do($location . $file, $name . $file);
}
} // EO addDirDo();
}
function zipIt($source, $target){
$za = new FlxZipArchive;
$res = $za->open($target, ZipArchive::CREATE);
if($res === TRUE) {
$za->addDir($source, basename($source));
$za->close();
}
else
echo 'Could not create a zip archive';
}
$the_folder = './Sales report';
$zip_file_name = './Sales report.docx';
//Don't forget to remove the trailing slash in folder
zipIt($the_folder,$zip_file_name,false);
The problem is that it includes the current directory,
Sales report/
file1.html
file2.html
Sub_Dir/
file19.html
But I just want
file1.html
file2.html
Sub_Dir/
file19.html
How to do that?