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