Page 1 of 1

Generating a zip file in php

Posted: Fri Apr 08, 2005 11:25 am
by dumola
I need to write a function that reads three files (ex: txt, gif, jpg) and creates a zip file containing them. Anyone have a clue to how this can be done?

Posted: Fri Apr 08, 2005 11:52 am
by neophyte
Use mkdir() to make a directory.
Use copy() to copy the files to the new directory.
You can use exec() to execute a shell command to zip the file.
Command could be something like "zip filename". Depends on your servers OS.

Hope this helps

Posted: Fri Apr 08, 2005 12:08 pm
by anjanesh
Currently direct compression using standard PHP libraries can be done only with bz2 - http://php.net/manual/en/ref.bzip2.php - this is OS independent.
But I guess most servers will have a zip compression tool to execute.

Posted: Sat Apr 09, 2005 2:58 am
by n00b Saibot
there is a script for this in the code-snippets section. :wink: