| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
| 20: | |
| 21: | include_once $GLOBALS['xoops']->path('class/downloader.php'); |
| 22: | include_once $GLOBALS['xoops']->path('class/class.zipfile.php'); |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | class XoopsZipDownloader extends XoopsDownloader |
| 35: | { |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | public function __construct($ext = '.zip', $mimyType = 'application/x-zip') |
| 45: | { |
| 46: | $this->archiver = new Zipfile(); |
| 47: | $this->ext = trim($ext); |
| 48: | $this->mimetype = trim($mimyType); |
| 49: | } |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | public function addFile($filepath, $newfilename = null) |
| 58: | { |
| 59: | |
| 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: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | public function addBinaryFile($filepath, $newfilename = null) |
| 74: | { |
| 75: | |
| 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: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | public function addFileData(&$data, $filename, $time = 0) |
| 91: | { |
| 92: | $this->archiver->addFile($data, $filename, $time); |
| 93: | } |
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | public function addBinaryFileData(&$data, $filename, $time = 0) |
| 103: | { |
| 104: | $this->addFileData($data, $filename, $time); |
| 105: | } |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | public function download($name, $gzip = true) |
| 114: | { |
| 115: | $this->_header($name . $this->ext); |
| 116: | echo $this->archiver->file(); |
| 117: | } |
| 118: | } |
| 119: | |