XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
tardownloader.php
1<?php
13
14
15if (!defined('XOOPS_ROOT_PATH')) {
16 exit();
17}
18
22include_once XOOPS_ROOT_PATH.'/class/downloader.php';
26include_once XOOPS_ROOT_PATH.'/class/class.tar.php';
27
28
30{
31
38 public function __construct($ext = '.tar.gz', $mimyType = 'application/x-gzip')
39 {
40 $this->archiver = new tar();
41 $this->ext = trim($ext);
42 $this->mimeType = trim($mimyType);
43 }
44
51 public function addFile($filepath, $newfilename=null)
52 {
53 $this->archiver->addFile($filepath);
54 if (isset($newfilename)) {
55 // dirty, but no other way
56 for ($i = 0; $i < $this->archiver->numFiles; $i++) {
57 if ($this->archiver->files[$i]['name'] == $filepath) {
58 $this->archiver->files[$i]['name'] = trim($newfilename);
59 break;
60 }
61 }
62 }
63 }
64
71 public function addBinaryFile($filepath, $newfilename=null)
72 {
73 $this->archiver->addFile($filepath, true);
74 if (isset($newfilename)) {
75 // dirty, but no other way
76 for ($i = 0; $i < $this->archiver->numFiles; $i++) {
77 if ($this->archiver->files[$i]['name'] == $filepath) {
78 $this->archiver->files[$i]['name'] = trim($newfilename);
79 break;
80 }
81 }
82 }
83 }
84
92 public function addFileData(&$data, $filename, $time=0)
93 {
94 $dummyfile = XOOPS_CACHE_PATH.'/dummy_'.time().'.html';
95 $fp = fopen($dummyfile, 'w');
96 fwrite($fp, $data);
97 fclose($fp);
98 $this->archiver->addFile($dummyfile);
99 unlink($dummyfile);
100
101 // dirty, but no other way
102 for ($i = 0; $i < $this->archiver->numFiles; $i++) {
103 if ($this->archiver->files[$i]['name'] == $dummyfile) {
104 $this->archiver->files[$i]['name'] = $filename;
105 if (0 != $time) {
106 $this->archiver->files[$i]['time'] = $time;
107 }
108 break;
109 }
110 }
111 }
112
120 public function addBinaryFileData(&$data, $filename, $time=0)
121 {
122 $dummyfile = XOOPS_CACHE_PATH.'/dummy_'.time().'.html';
123 $fp = fopen($dummyfile, 'wb');
124 fwrite($fp, $data);
125 fclose($fp);
126 $this->archiver->addFile($dummyfile, true);
127 unlink($dummyfile);
128
129 // dirty, but no other way
130 for ($i = 0; $i < $this->archiver->numFiles; $i++) {
131 if ($this->archiver->files[$i]['name'] == $dummyfile) {
132 $this->archiver->files[$i]['name'] = $filename;
133 if (0 != $time) {
134 $this->archiver->files[$i]['time'] = $time;
135 }
136 break;
137 }
138 }
139 }
140
147 public function download($name, $gzip = true)
148 {
149 $file = $this->archiver->toTarOutput($name.$this->ext, $gzip);
150 $this->_header($name.$this->ext);
151 header('Content-Type: application/x-tar') ;
152 header('Content-Length: ' . (float)@strlen($file)) ;
153 echo $file;
154 }
155}
_header($filename)
addBinaryFileData(&$data, $filename, $time=0)
addFileData(&$data, $filename, $time=0)
download($name, $gzip=true)
addFile($filepath, $newfilename=null)
addBinaryFile($filepath, $newfilename=null)
__construct($ext='.tar.gz', $mimyType='application/x-gzip')