Asbjorn Grandt - 2011-08-16 10:30:34 -
In reply to message 1 from Szenogradi Norbert
There are a few problems with your script.
One, the path given as the Zip path must be valid, meaning no double or leading '/' etc. Your script does add a few extra slashes at times.
You can use ZipStream::getRelativePath($path) to help clean those. That function is identical to my RelativePath class also here on PHPClasses. Additionally ZipStream::pathJoin($path1, $path2); will also work better than just "{$path1}/{$path2}".
Second, all files are added the number of times matching the depth of the file, meaning a file in the 5th subdirectory is added 5 times with your script. You are traversing the tree structure fully for each directory, because you are starting by building the directory tree itself.
Instead, you can use ZipStream to add a full directory tree.
$zip->addDirectoryContent($realPath, $zipPath, $recursive)
i.e.
$zip->addDirectoryContent("testing/", "testing/", TRUE);
You can omit the $recursive parameter, as it defaults to TRUE.
I'll have to look into hardening the functions against the invalid paths as well as try to keep track of duplicates.