XOOPS  2.6.0
tardownloader.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
24 {
31  public function __construct($ext = '.tar.gz', $mimyType = 'application/x-gzip')
32  {
33  $this->archiver = new tar();
34  $this->ext = trim($ext);
35  $this->mimeType = trim($mimyType);
36  }
37 
46  public function addFile($filepath, $newfilename = null)
47  {
48  $result = $this->archiver->addFile($filepath);
49  if ($result === false) {
50  return false;
51  }
52  if (isset($newfilename)) {
53  // dirty, but no other way
54  for ($i = 0; $i < $this->archiver->numFiles; ++$i) {
55  if ($this->archiver->files[$i]['name'] == $filepath) {
56  $this->archiver->files[$i]['name'] = trim($newfilename);
57  break;
58  }
59  }
60  }
61  }
62 
71  public function addBinaryFile($filepath, $newfilename = null)
72  {
73  $result = $this->archiver->addFile($filepath, true);
74  if ($result === false) {
75  return false;
76  }
77  if (isset($newfilename)) {
78  // dirty, but no other way
79  for ($i = 0; $i < $this->archiver->numFiles; ++$i) {
80  if ($this->archiver->files[$i]['name'] == $filepath) {
81  $this->archiver->files[$i]['name'] = trim($newfilename);
82  break;
83  }
84  }
85  }
86  }
87 
97  public function addFileData(&$data, $filename, $time = 0)
98  {
99  $dummyfile = \XoopsBaseConfig::get('caches-path') . '/dummy_' . time() . '.html';
100  $fp = @fopen($dummyfile, 'w');
101  if ($fp === false) {
102  return false;
103  }
104  fwrite($fp, $data);
105  fclose($fp);
106  $result = $this->archiver->addFile($dummyfile);
107  unlink($dummyfile);
108  if ($result === false) {
109  return false;
110  }
111  // dirty, but no other way
112  for ($i = 0; $i < $this->archiver->numFiles; ++$i) {
113  if ($this->archiver->files[$i]['name'] == $dummyfile) {
114  $this->archiver->files[$i]['name'] = $filename;
115  if ($time != 0) {
116  $this->archiver->files[$i]['time'] = $time;
117  }
118  break;
119  }
120  }
121  }
122 
132  public function addBinaryFileData(&$data, $filename, $time = 0)
133  {
134  $dummyfile = \XoopsBaseConfig::get('caches-path') . '/dummy_' . time() . '.html';
135  $fp = @fopen($dummyfile, 'wb');
136  if ($fp === false) {
137  return false;
138  }
139  fwrite($fp, $data);
140  fclose($fp);
141  $result = $this->archiver->addFile($dummyfile, true);
142  unlink($dummyfile);
143  if ($result === false) {
144  return false;
145  }
146  // dirty, but no other way
147  for ($i = 0; $i < $this->archiver->numFiles; ++$i) {
148  if ($this->archiver->files[$i]['name'] == $dummyfile) {
149  $this->archiver->files[$i]['name'] = $filename;
150  if ($time != 0) {
151  $this->archiver->files[$i]['time'] = $time;
152  }
153  break;
154  }
155  }
156  }
157 
166  public function download($name, $gzip = true)
167  {
168  $this->_header($name . $this->ext);
169  $str = $this->archiver->toTarOutput($name . $this->ext, $gzip);
170  if ($str !== false) {
171  echo $str;
172  }
173  }
174 }
download($name, $gzip=true)
$i
Definition: dialog.php:68
$result
Definition: pda.php:33
addBinaryFile($filepath, $newfilename=null)
__construct($ext= '.tar.gz', $mimyType= 'application/x-gzip')
static get($name)
addFile($filepath, $newfilename=null)
addBinaryFileData(&$data, $filename, $time=0)
_header($filename)
Definition: downloader.php:53
addFileData(&$data, $filename, $time=0)