Home « Server software «
Documentation: shared/zipfile.php
class zipfile - Create a zip archive file
This script is useful to package several files on the fly into a single downloaded archive.Example:
// build a zip archive
include_once 'zipfile.php';
$zipfile = new zipfile();
// place all files into a single directory
$zipfile->store('files/', time());
// archive each file
foreach($items as $id => $name) {
// read file content
if($content = Safe::file_get_contents($file_path.$name)) {
// add the binary data stored in the string 'filedata'
$zipfile->store('files/'.$name, Safe::filemtime($file_path.$name), $content);
}
}
// suggest a download
Safe::header('Content-Type: application/zip');
Safe::header('Content-Disposition: attachment; filename="download.zip"');
// send the archive content
echo $zipfile->get();
return;
This script is a reference file of this system.
Voir aussi:
Licence: GNU Lesser General Public License
Auteurs:
- Bernard Paques bernard.paques@bigfoot.com
- Eric Mueller http://www.themepark.com/
- Denis O.Philippov webmaster@atlant.ru, http://www.atlant.ru
shared/zipfile.php - Compressed data
shared/zipfile.php - File descriptors
shared/zipfile.php - Number of entries
deflate() - Deflate one file
function deflate($name, $date, $data=NULL)
- $name - string the file name, with any directory information if any
- $date - int the time stamp of the file, generally obtained through Safe::filemtime()
- $data=NULL - string the actual content of the file to be compressed
store() - Store one file without compressing it
function store($name, $date, $data=NULL)
- $name - string the file name, with any directory information if any
- $date - int the time stamp of the file, generally obtained through
Safe::filemtime() - $data=NULL - string the actual content of the file to be compressed
- returns void
get() - Dump the archive content
function get()
- returns the bytes to be saved into a file, or sent accross the network