Generating a zip file in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dumola
Forum Newbie
Posts: 1
Joined: Thu Apr 07, 2005 5:51 am

Generating a zip file in php

Post 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?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

there is a script for this in the code-snippets section. :wink:
Post Reply