XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
zipdownloader.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
22 include_once $GLOBALS['xoops']->path('class/downloader.php');
23 include_once $GLOBALS['xoops']->path('class/class.zipfile.php');
24 
36 {
45  function XoopsZipDownloader($ext = '.zip', $mimyType = 'application/x-zip')
46  {
47  $this->archiver = new zipfile();
48  $this->ext = trim($ext);
49  $this->mimeType = trim($mimyType);
50  }
57  function addFile($filepath, $newfilename = null)
58  {
59  // Read in the file's contents
60  $fp = fopen($filepath, "r");
61  $data = fread($fp, filesize($filepath));
62  fclose($fp);
63  $filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath;
64  $this->archiver->addFile($data, $filename, filemtime($filename));
65  }
66 
73  function addBinaryFile($filepath, $newfilename = null)
74  {
75  // Read in the file's contents
76  $fp = fopen($filepath, "rb");
77  $data = fread($fp, filesize($filepath));
78  fclose($fp);
79  $filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath;
80  $this->archiver->addFile($data, $filename, filemtime($filename));
81  }
82 
90  function addFileData(&$data, $filename, $time = 0)
91  {
92  $this->archiver->addFile($data, $filename, $time);
93  }
94 
102  function addBinaryFileData(&$data, $filename, $time = 0)
103  {
104  $this->addFileData($data, $filename, $time);
105  }
106 
113  function download($name, $gzip = true)
114  {
115  $this->_header($name . $this->ext);
116  echo $this->archiver->file();
117  }
118 }
119 ?>