Subversion Repositories eFlore/Applications.cel

Rev

Rev 1624 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1604 raphael 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP Version 4                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2002 The PHP Group                                |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.02 of the PHP license,      |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
16
// | Author: Xavier Noguer <xnoguer@php.net>                              |
17
// | Based on OLE::Storage_Lite by Kawai, Takanori                        |
18
// +----------------------------------------------------------------------+
19
//
20
// $Id: File.php 252097 2008-02-02 21:00:37Z schmidt $
21
 
22
 
23
require_once 'OLE/PPS.php';
24
require_once 'System.php';
25
 
26
/**
27
* Class for creating File PPS's for OLE containers
28
*
29
* @author   Xavier Noguer <xnoguer@php.net>
30
* @category Structures
31
* @package  OLE
32
*/
33
class OLE_PPS_File extends OLE_PPS
34
{
35
    /**
36
    * The temporary dir for storing the OLE file
37
    * @var string
38
    */
39
    var $_tmp_dir;
40
 
41
    /**
42
    * The constructor
43
    *
44
    * @access public
45
    * @param string $name The name of the file (in Unicode)
46
    * @see OLE::Asc2Ucs()
47
    */
3473 killian 48
    function __construct($name)
1604 raphael 49
    {
1624 aurelien 50
        $this->_tmp_dir = @System::tmpdir();
3473 killian 51
        parent::__construct(
1604 raphael 52
            null,
53
            $name,
54
            OLE_PPS_TYPE_FILE,
55
            null,
56
            null,
57
            null,
58
            null,
59
            null,
60
            '',
61
            array());
62
    }
63
 
64
    /**
65
    * Sets the temp dir used for storing the OLE file
66
    *
67
    * @access public
68
    * @param string $dir The dir to be used as temp dir
69
    * @return true if given dir is valid, false otherwise
70
    */
71
    function setTempDir($dir)
72
    {
73
        if (is_dir($dir)) {
74
            $this->_tmp_dir = $dir;
75
            return true;
76
        }
77
        return false;
78
    }
79
 
80
    /**
81
    * Initialization method. Has to be called right after OLE_PPS_File().
82
    *
83
    * @access public
84
    * @return mixed true on success. PEAR_Error on failure
85
    */
86
    function init()
87
    {
88
        $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
89
        $fh = @fopen($this->_tmp_filename, "w+b");
90
        if ($fh == false) {
91
            return $this->raiseError("Can't create temporary file");
92
        }
93
        $this->_PPS_FILE = $fh;
94
        if ($this->_PPS_FILE) {
95
            fseek($this->_PPS_FILE, 0);
96
        }
97
 
98
        return true;
99
    }
100
 
101
    /**
102
    * Append data to PPS
103
    *
104
    * @access public
105
    * @param string $data The data to append
106
    */
107
    function append($data)
108
    {
109
        if ($this->_PPS_FILE) {
110
            fwrite($this->_PPS_FILE, $data);
111
        } else {
112
            $this->_data .= $data;
113
        }
114
    }
115
 
116
    /**
117
     * Returns a stream for reading this file using fread() etc.
118
     * @return  resource  a read-only stream
119
     */
120
    function getStream()
121
    {
122
        $this->ole->getStream($this);
123
    }
124
}
125
?>