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,v 1.12 2008/02/02 21:00:37 schmidt Exp $
21
22
23require_once( dirname(__FILE__) . '/../PPS.php');
24require_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*/
33class 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    */
48    public function __construct($name)
49    {
50        $tempDir = new System();
51        $this->_tmp_dir = $tempDir->tmpdir();
52        $this->OLE_PPS(
53            null,
54            $name,
55            OLE_PPS_TYPE_FILE,
56            null,
57            null,
58            null,
59            null,
60            null,
61            '',
62            array());
63    }
64
65    /**
66    * The constructor
67    *
68    * @access public
69    * @param string $name The name of the file (in Unicode)
70    * @see OLE::Asc2Ucs()
71    */
72    // function OLE_PPS_File($name)
73    // {
74    // 	$tempDir = new System();
75    //     $this->_tmp_dir = $tempDir->tmpdir();
76    //     $this->OLE_PPS(
77    //         null,
78    //         $name,
79    //         OLE_PPS_TYPE_FILE,
80    //         null,
81    //         null,
82    //         null,
83    //         null,
84    //         null,
85    //         '',
86    //         array());
87    // }
88
89    /**
90    * Sets the temp dir used for storing the OLE file
91    *
92    * @access public
93    * @param string $dir The dir to be used as temp dir
94    * @return true if given dir is valid, false otherwise
95    */
96    function setTempDir($dir)
97    {
98        if (is_dir($dir)) {
99            $this->_tmp_dir = $dir;
100            return true;
101        }
102        return false;
103    }
104
105    /**
106    * Initialization method. Has to be called right after OLE_PPS_File().
107    *
108    * @access public
109    * @return mixed true on success. PEAR_Error on failure
110    */
111    function init()
112    {
113        $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
114        $fh = @fopen($this->_tmp_filename, "w+b");
115        if ($fh == false) {
116            return $this->raiseError("Can't create temporary file");
117        }
118        $this->_PPS_FILE = $fh;
119        if ($this->_PPS_FILE) {
120            fseek($this->_PPS_FILE, 0);
121        }
122
123        return true;
124    }
125
126    /**
127    * Append data to PPS
128    *
129    * @access public
130    * @param string $data The data to append
131    */
132    function append($data)
133    {
134        if ($this->_PPS_FILE) {
135            fwrite($this->_PPS_FILE, $data);
136        } else {
137            $this->_data .= $data;
138        }
139    }
140
141    /**
142     * Returns a stream for reading this file using fread() etc.
143     * @return  resource  a read-only stream
144     */
145    function getStream()
146    {
147        $this->ole->getStream($this);
148    }
149}
150?>
151