summaryrefslogtreecommitdiff
path: root/test/index.php
blob: ec89f769e0566b617cb76a03d6d3eac066a778d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

# load zipstream class
require '../zipstream.php';

# get path to current file
$pwd = dirname(__FILE__);

# add some random files
$files = array(
  '../extras/zip-appnote-6.3.1-20070411.txt',
  '../zipstream.php',
);

# create new zip stream object
$zip = new ZipStream('test.zip', array(
  'comment' => 'this is a zip file comment.  hello?'
));

# common file options
$file_opt = array(
  # file creation time (2 hours ago)
  'time'    => time() - 2 * 3600,

  # file comment
  'comment' => 'this is a file comment. hi!',
);

# add files under folder 'asdf'
foreach ($files as $file) {
  # build absolute path and get file data
  $path = ($file[0] == '/') ? $file : "$pwd/$file";
  $data = file_get_contents($path);

  # add file to archive
  $zip->add_file('asdf/' . basename($file), $data, $file_opt);
}

# add same files again wihtout a folder
foreach ($files as $file) {
  # build absolute path and get file data
  $path = ($file[0] == '/') ? $file : "$pwd/$file";
  $data = file_get_contents($path);

  # add file to archive
  $zip->add_file(basename($file), $data, $file_opt);
}

# finish archive
$zip->finish();

?>