XOOPS  2.6.0
zipdownloader.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 
32 {
42  public function __construct($ext = '.zip', $mimyType = 'application/x-zip')
43  {
44  $this->archiver = new zipfile();
45  $this->ext = trim($ext);
46  $this->mimeType = trim($mimyType);
47  }
48 
57  public function addFile($filepath, $newfilename = null)
58  {
59  // Read in the file's contents
60  $fp = @fopen($filepath, "r");
61  if ($fp === false) {
62  return false;
63  }
64  $data = fread($fp, filesize($filepath));
65  fclose($fp);
66  $filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath;
67  $result = $this->archiver->addFile($data, $filename, filemtime($filename));
68  return $result;
69  }
70 
79  public function addBinaryFile($filepath, $newfilename = null)
80  {
81  // Read in the file's contents
82  $fp = @fopen($filepath, "rb");
83  if ($fp === false) {
84  return false;
85  }
86  $data = fread($fp, filesize($filepath));
87  fclose($fp);
88  $filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath;
89  $result = $this->archiver->addFile($data, $filename, filemtime($filename));
90  return $result;
91  }
92 
102  public function addFileData(&$data, $filename, $time = 0)
103  {
104  $result = $this->archiver->addFile($data, $filename, $time);
105  return $result;
106  }
107 
117  public function addBinaryFileData(&$data, $filename, $time = 0)
118  {
119  $result = $this->addFileData($data, $filename, $time);
120  return $result;
121  }
122 
131  public function download($name, $gzip = true)
132  {
133  $this->_header($name . $this->ext);
134  $result = $this->archiver->file();
135  if ($result !== false) {
136  echo $result;
137  }
138  }
139 }
$result
Definition: pda.php:33
download($name, $gzip=true)
addBinaryFileData(&$data, $filename, $time=0)
addFileData(&$data, $filename, $time=0)
__construct($ext= '.zip', $mimyType= 'application/x-zip')
addFile($filepath, $newfilename=null)
_header($filename)
Definition: downloader.php:53
addBinaryFile($filepath, $newfilename=null)