Showing posts with label zip. Show all posts
Showing posts with label zip. Show all posts

Monday, March 7, 2011

Create zip file on the fly with PHP

Hi,

This post is about creating zip files on the fly. I have found a class over the internet which allows you to do that. First of all you need to download the class file. Click here to download the class file. Once you have downloaded the code, create another file example.php and put the following:


<?php
require "zip.class.php";
$zipfile = new zipfile;

function make_archieve($location,$type,$filename,$zipfile)
{
if($type=="dir"){
$dir=opendir($location);
$i=0;
while($files=readdir($dir)){
if($i>1 && filetype($location."/".$files)!="dir"){
$tmp_location=str_replace("./","",$location);
$tmp_location=$tmp_location."/";
if($tmp_location=="./"){$tmp_location="";}
$zipfile->create_file(file_get_contents($location."/".$files), $tmp_location.$files);