Generate zip file for download
Posted: Fri Jun 27, 2008 10:41 am
Hi everyone, I am working on an application to generate resumes of employees from a MySQL Database. Currently I generate the Word documents for the resumes (That is the format they asked me for) using COM libraries. I generate the CV's inside a folder in my web server but now I would like to zip them and put them available for download. I checked in the php.net site for reference (http://lt.php.net/manual/en/ref.zip.php), and I found the following code, which seems to do what I need:
The problem is, that I have never used classes in PHP
how could I use that code, so that I can zip all of my resumes that are inside an specific folder?
Thanks!
Code: Select all
class MyZipArchive extends ZipArchive
{
/**
*
* Adds a directory recursively.
*
* @param string $filename The path to the file to add.
*
* @param string $localname Local name inside ZIP archive.
*
*/
public function addDir($filename, $localname)
{
$this->addEmptyDir($localname);
$iter = new RecursiveDirectoryIterator($filename);
foreach ($iter as $fileinfo) {
if (! $fileinfo->isFile() && !$fileinfo->isDir()) {
continue;
}
$method = $fileinfo->isFile() ? 'addFile' : 'addDir';
$this->$method($fileinfo->getPathname(), $localname . '/' .
$fileinfo->getFilename());
}
}
}
Thanks!