Click to See Complete Forum and Search --> : PEAR File_Archive package question


foxhunt99
March 25th, 2008, 12:09 PM
Hi,
I am trying to use the Pear File_Archive package to manupilate some zip files. I want to write a loop and keep adding files to a zip file until the loop is done.

I did the following code inside the while loop:

$src = File_Archive::read($patchtofile1);
$dest=File_Archive::toArchive("./data.zip", File_Archive::toFiles());
File_Archive::extract($src, $dest);

This doesn't work because data.zip is replaced in every loop. Anyone know the correct way of doing this?

Also I tried to zip a whole directory. I tested by creating a directory which contains 1.txt and 2.txt files. and used code:
$source=File_Archive::read("./tempfolder/");
$dest=File_Archive::toArchive("./data.zip", File_Archive::toFiles());
File_Archive::extract($source, $dest);

This created a data.zip file, but it contains three copies of 2.txt files for some reason.

Thanks

PeejAvery
March 25th, 2008, 05:00 PM
You don't need to use any loop to add files. You can pass an array of all the files and folders you want to add.

http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/