File.php 3.4 KB

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