Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
4
/**
5
 * Writer to the standard output
6
 * It will concatenate the files that it receive
7
 * It may send some headers, but will do so only for the first file
8
 *
9
 * PHP versions 4 and 5
10
 *
11
 * This library is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU Lesser General Public
13
 * License as published by the Free Software Foundation; either
14
 * version 2.1 of the License, or (at your option) any later version.
15
 *
16
 * This library is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19
 * Lesser General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Lesser General Public
22
 * License along with this library; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
24
 *
25
 * @category   File Formats
26
 * @package    File_Archive
27
 * @author     Vincent Lascaux <vincentlascaux@php.net>
28
 * @copyright  1997-2005 The PHP Group
29
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL
30
 * @version    CVS: $Id: Output.php,v 1.9 2007/01/07 21:49:48 pfischer Exp $
31
 * @link       http://pear.php.net/package/File_Archive
32
 */
33
 
34
require_once "File/Archive/Writer.php";
35
 
36
/**
37
 * Writer to the standard output
38
 * It will concatenate the files that it receive
39
 * It may send some headers, but will do so only for the first file
40
 */
41
class File_Archive_Writer_Output extends File_Archive_Writer
42
{
43
    /**
44
     * @var    bool If true, the Content-type and Content-disposition headers
45
     *         will be sent. The file will be considered as an attachment and
46
     *         the MIME will be deduced from its extension
47
     * @access private
48
     */
49
    var $sendHeaders;
50
 
51
    /**
52
     * @param $sendHeaders see the variable
53
     */
54
    function File_Archive_Writer_Output($sendHeaders = true)
55
    {
56
        $this->sendHeaders = $sendHeaders;
57
    }
58
    /**
59
     * @see File_Archive_Writer::newFile()
60
     */
61
    function newFile($filename, $stat = array(), $mime = "application/octet-stream")
62
    {
63
        if ($this->sendHeaders) {
64
            if(headers_sent()) {
65
                return PEAR::raiseError(
66
                    'The headers have already been sent. '.
67
                    'Use File_Archive::toOutput(false) to write '.
68
                    'to output without sending headers');
69
            }
70
 
71
            header("Content-type: $mime");
72
            header("Content-disposition: attachment; filename=\"$filename\"");
73
            $this->sendHeaders = false;
74
        }
75
    }
76
    /**
77
     * @see File_Archive_Writer::newFileNeedsMIME
78
     */
79
    function newFileNeedsMIME()
80
    {
81
        return $this->sendHeaders;
82
    }
83
    /**
84
     * @see File_Archive_Writer::writeData()
85
     */
86
    function writeData($data) { echo $data; }
87
    /**
88
     * @see File_Archive_Writer::writeFile()
89
     */
90
    function writeFile($filename) { readfile($filename); }
91
}
92
 
93
?>