| [ Index ] |
PHP Cross Reference of Xoops v2.4.5 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Send tar files through a http socket 4 * 5 * You may not change or alter any portion of this comment or credits 6 * of supporting developers from this source code or any supporting source code 7 * which is considered copyrighted (c) material of the original comment or credit authors. 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ 13 * @license http://www.fsf.org/copyleft/gpl.html GNU public license 14 * @package kernel 15 * @since 2.0.0 16 * @author Kazumi Ono (http://www.myweb.ne.jp/, http://jp.xoops.org/) 17 * @version $Id: tardownloader.php 4897 2010-06-19 02:55:48Z phppp $ 18 */ 19 defined('XOOPS_ROOT_PATH') or die('Restricted access'); 20 21 /** 22 * base class 23 */ 24 include_once XOOPS_ROOT_PATH . '/class/downloader.php'; 25 /** 26 * Class to handle tar files 27 */ 28 include_once XOOPS_ROOT_PATH . '/class/class.tar.php'; 29 30 class XoopsTarDownloader extends XoopsDownloader 31 { 32 /** 33 * Constructor 34 * 35 * @param string $ext file extension 36 * @param string $mimyType Mimetype 37 */ 38 function XoopsTarDownloader($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 45 /** 46 * Add a file to the archive 47 * 48 * @param string $filepath Full path to the file 49 * @param string $newfilename Filename (if you don't want to use the original) 50 */ 51 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 65 /** 66 * Add a binary file to the archive 67 * 68 * @param string $filepath Full path to the file 69 * @param string $newfilename Filename (if you don't want to use the original) 70 */ 71 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 85 /** 86 * Add a dummy file to the archive 87 * 88 * @param string $data Data to write 89 * @param string $filename Name for the file in the archive 90 * @param integer $time 91 */ 92 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 // dirty, but no other way 101 for($i = 0; $i < $this->archiver->numFiles; $i ++) { 102 if ($this->archiver->files[$i]['name'] == $dummyfile) { 103 $this->archiver->files[$i]['name'] = $filename; 104 if ($time != 0) { 105 $this->archiver->files[$i]['time'] = $time; 106 } 107 break; 108 } 109 } 110 } 111 112 /** 113 * Add a binary dummy file to the archive 114 * 115 * @param string $data Data to write 116 * @param string $filename Name for the file in the archive 117 * @param integer $time 118 */ 119 function addBinaryFileData(&$data, $filename, $time = 0) 120 { 121 $dummyfile = XOOPS_CACHE_PATH . '/dummy_' . time() . '.html'; 122 $fp = fopen($dummyfile, 'wb'); 123 fwrite($fp, $data); 124 fclose($fp); 125 $this->archiver->addFile($dummyfile, true); 126 unlink($dummyfile); 127 // dirty, but no other way 128 for($i = 0; $i < $this->archiver->numFiles; $i ++) { 129 if ($this->archiver->files[$i]['name'] == $dummyfile) { 130 $this->archiver->files[$i]['name'] = $filename; 131 if ($time != 0) { 132 $this->archiver->files[$i]['time'] = $time; 133 } 134 break; 135 } 136 } 137 } 138 139 /** 140 * Send the file to the client 141 * 142 * @param string $name Filename 143 * @param boolean $gzip Use GZ compression 144 */ 145 function download($name, $gzip = true) 146 { 147 $this->_header($name . $this->ext); 148 echo $this->archiver->toTarOutput($name . $this->ext, $gzip); 149 } 150 } 151 152 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 01:39:09 2010 |