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$ 21 22/** 23* Class for creating File PPS's for OLE containers 24* 25* @author Xavier Noguer <xnoguer@php.net> 26* @category Structures 27* @package OLE 28*/ 29class OLE_PPS_File extends OLE_PPS 30{ 31 /** 32 * The temporary dir for storing the OLE file 33 * @var string 34 */ 35 var $_tmp_dir; 36 37 /** 38 * The constructor 39 * 40 * @access public 41 * @param string $name The name of the file (in Unicode) 42 * @see OLE::Asc2Ucs() 43 */ 44 function __construct($name) 45 { 46 $this->_tmp_dir = ''; 47 $this->OLE_PPS( 48 null, 49 $name, 50 OLE_PPS_TYPE_FILE, 51 null, 52 null, 53 null, 54 null, 55 null, 56 '', 57 array()); 58 } 59 60 /** 61 * Sets the temp dir used for storing the OLE file 62 * 63 * @access public 64 * @param string $dir The dir to be used as temp dir 65 * @return true if given dir is valid, false otherwise 66 */ 67 function setTempDir($dir) 68 { 69 if (is_dir($dir)) { 70 $this->_tmp_dir = $dir; 71 return true; 72 } 73 return false; 74 } 75 76 /** 77 * Initialization method. Has to be called right after OLE_PPS_File(). 78 * 79 * @access public 80 * @return mixed true on success. PEAR_Error on failure 81 */ 82 function init() 83 { 84 $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File"); 85 $fh = @fopen($this->_tmp_filename, "w+b"); 86 if ($fh == false) { 87 return $this->raiseError("Can't create temporary file"); 88 } 89 $this->_PPS_FILE = $fh; 90 if ($this->_PPS_FILE) { 91 fseek($this->_PPS_FILE, 0); 92 } 93 } 94 95 /** 96 * Append data to PPS 97 * 98 * @access public 99 * @param string $data The data to append 100 */ 101 function append($data) 102 { 103 if ($this->_PPS_FILE) { 104 fwrite($this->_PPS_FILE, $data); 105 } 106 else { 107 $this->_data .= $data; 108 } 109 } 110} 111