File.php 3.5 KB

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