XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
zipdownloader.php
1<?php
13
14if (!defined('XOOPS_ROOT_PATH')) {
15 exit();
16}
17include_once XOOPS_ROOT_PATH.'/class/downloader.php';
18include_once XOOPS_ROOT_PATH.'/class/class.zipfile.php';
19
21{
22 public function __construct($ext = '.zip', $mimyType = 'application/x-zip')
23 {
24 $this->archiver = new zipfile();
25 $this->ext = trim($ext);
26 $this->mimeType = trim($mimyType);
27 }
28
29 public function addFile($filepath, $newfilename=null)
30 {
31 // Read in the file's contents
32 $fp = fopen($filepath, 'rb');
33 $data = fread($fp, filesize($filepath));
34 fclose($fp);
35 $filename = (isset($newfilename) && '' !== trim($newfilename)) ? trim($newfilename) : $filepath;
36 $filepath = is_file($filename) ? $filename : $filepath;
37 $this->archiver->addFile($data, $filename, filemtime($filepath));
38 }
39
40 public function addBinaryFile($filepath, $newfilename=null)
41 {
42 // Read in the file's contents
43 $fp = fopen($filepath, 'rb');
44 $data = fread($fp, filesize($filepath));
45 fclose($fp);
46 $filename = (isset($newfilename) && '' !== trim($newfilename)) ? trim($newfilename) : $filepath;
47 $filepath = is_file($filename) ? $filename : $filepath;
48 $this->archiver->addFile($data, $filename, filemtime($filepath));
49 }
50
51 public function addFileData(&$data, $filename, $time=0)
52 {
53 $this->archiver->addFile($data, $filename, $time);
54 }
55
56 public function addBinaryFileData(&$data, $filename, $time=0)
57 {
58 $this->addFileData($data, $filename, $time);
59 }
60
61 public function download($name, $gzip = true)
62 {
63 $file = $this->archiver->file();
64 $this->_header($name.$this->ext);
65 header('Content-Type: application/zip') ;
66 header('Content-Length: ' . (float)@strlen($file)) ;
67 echo $file;
68 }
69}
_header($filename)
addBinaryFileData(&$data, $filename, $time=0)
addFileData(&$data, $filename, $time=0)
download($name, $gzip=true)
addFile($filepath, $newfilename=null)
addBinaryFile($filepath, $newfilename=null)