示例#1
0
文件: Root.php 项目: roojs/pear
 /**
  * Method for saving the whole OLE container (including files).
  * In fact, if called with an empty argument (or '-'), it saves to a
  * temporary file and then outputs it's contents to stdout.
  *
  * @param string $filename The name of the file where to save the OLE container
  * @access public
  * @return mixed true on success, PEAR_Error on failure
  */
 function save($filename)
 {
     // Initial Setting for saving
     $this->_BIG_BLOCK_SIZE = pow(2, isset($this->_BIG_BLOCK_SIZE) ? $this->_adjust2($this->_BIG_BLOCK_SIZE) : 9);
     $this->_SMALL_BLOCK_SIZE = pow(2, isset($this->_SMALL_BLOCK_SIZE) ? $this->_adjust2($this->_SMALL_BLOCK_SIZE) : 6);
     // Open temp file if we are sending output to stdout
     if ($filename == '-' || $filename == '') {
         $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
         $this->_FILEH_ = @fopen($this->_tmp_filename, "w+b");
         if ($this->_FILEH_ == false) {
             return $this->raiseError("Can't create temporary file.");
         }
     } else {
         $this->_FILEH_ = @fopen($filename, "wb");
         if ($this->_FILEH_ == false) {
             return $this->raiseError("Can't open {$filename}. It may be in use or protected.");
         }
     }
     // Make an array of PPS's (for Save)
     $aList = array();
     OLE_PPS_Root::_savePpsSetPnt($aList, array($this));
     // calculate values for header
     list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList);
     //, $rhInfo);
     // Save Header
     $this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
     // Make Small Data string (write SBD)
     $this->_data = $this->_makeSmallData($aList);
     // Write BB
     $this->_saveBigData($iSBDcnt, $aList);
     // Write PPS
     $this->_savePps($aList);
     // Write Big Block Depot and BDList and Adding Header informations
     $this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
     // Close File, send it to stdout if necessary
     if ($filename == '-' || $filename == '') {
         fseek($this->_FILEH_, 0);
         fpassthru($this->_FILEH_);
         @fclose($this->_FILEH_);
         // Delete the temporary file.
         @unlink($this->_tmp_filename);
     } else {
         @fclose($this->_FILEH_);
     }
     return true;
 }