You are not logged in.

#1 2009-01-12 05:52:29

delacruz
Member
From: /home/houston
Registered: 2007-12-09
Posts: 102

php: zip_files->pipe_to_download

I have a large amount of files in a given folder.  I would like to do the following.

1) zip up files or folder if its easier
2) "pipe" the output of the zip file to the user as a download link

thats it.  I dont want to zip file to be stored on the server.  The file will be to big.

i know how to make a zip file

<?php

$zip = new ZipArchive();
$filename = "./test112.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}
$zip->addFile($thisdir ."./file01.txt");
$zip->addFile($thisdir ."./file02.txt");
$zip->addFile($thisdir ."./file03.txt");
$zip->close();
?>

I just dont know how exactly to send the output to the user as it is being compressed.

Offline

#2 2009-01-12 22:01:16

oliwer
Member
From: Paris
Registered: 2007-06-30
Posts: 153
Website

Re: php: zip_files->pipe_to_download

Something like this :

<?php
header('Content-type: application/zip');
readfile('$filename');
?>

Offline

Board footer

Powered by FluxBB