Vendor/phpspreadsheet/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLE.php
public function read($file)
    {
        $fh = fopen($file, 'r');
        if (!$fh) {
            throw new ReaderException("Can't open file $file");
        }
        $this->_file_handle = $fh;

        $signature = fread($fh, 8);
        if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
            throw new ReaderException("File doesn't seem to be an OLE container.");
        }
        fseek($fh, 28);
        if (fread($fh, 2) != "\xFE\xFF") {
            // This shouldn't be a problem in practice
            throw new ReaderException('Only Little-Endian encoding is supported.');
        }
        // Size of blocks and short blocks in bytes
        $this->bigBlockSize = pow(2, self::_readInt2($fh));
        $this->smallBlockSize = pow(2, self::_readInt2($fh));

        // Skip UID, revision number and version number
        fseek($fh, 44);
        // Number of blocks in Big Block Allocation Table
        $bbatBlockCount = self::_readInt4($fh);

        // Root chain 1st block
        $directoryFirstBlockId = self::_readInt4($fh);

        // Skip unused bytes
        fseek($fh, 56);
        // Streams shorter than this are stored using small blocks
        $this->bigBlockThreshold = self::_readInt4($fh);
        // Block id of first sector in Short Block Allocation Table
        $sbatFirstBlockId = self::_readInt4($fh);
        // Number of blocks in Short Block Allocation Table
        $sbbatBlockCount = self::_readInt4($fh);
        // Block id of first sector in Master Block Allocation Table
        $mbatFirstBlockId = self::_readInt4($fh);
        // Number of blocks in Master Block Allocation Table
        $mbbatBlockCount = self::_readInt4($fh);
        $this->bbat = [];

        // Remaining 4 * 109 bytes of current block is beginning of Master
        // Block Allocation Table
        $mbatBlocks = [];
        for ($i = 0; $i < 109; ++$i) {
            $mbatBlocks[] = self::_readInt4($fh);
        }

        // Read rest of Master Block Allocation Table (if any is left)
        $pos = $this->_getBlockOffset($mbatFirstBlockId);
        for ($i = 0; $i < $mbbatBlockCount; ++$i) {
            fseek($fh, $pos);
            for ($j = 0; $j < $this->bigBlockSize / 4 - 1; ++$j) {
                $mbatBlocks[] = self::_readInt4($fh);
            }
            // Last block id in each block points to next block
            $pos = $this->_getBlockOffset(self::_readInt4($fh));
        }

        // Read Big Block Allocation Table according to chain specified by $mbatBlocks
        for ($i = 0; $i < $bbatBlockCount; ++$i) {
            $pos = $this->_getBlockOffset($mbatBlocks[$i]);
            fseek($fh, $pos);
            for ($j = 0; $j < $this->bigBlockSize / 4; ++$j) {
                $this->bbat[] = self::_readInt4($fh);
            }
        }

        // Read short block allocation table (SBAT)
        $this->sbat = [];
        $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
        $sbatFh = $this->getStream($sbatFirstBlockId);
        for ($blockId = 0; $blockId < $shortBlockCount; ++$blockId) {
            $this->sbat[$blockId] = self::_readInt4($sbatFh);
        }
        fclose($sbatFh);

        $this->_readPpsWks($directoryFirstBlockId);

        return true;
    }
public function read($file)
    {
        $fh = fopen($file, 'r');
        if (!$fh) {
            throw new ReaderException("Can't open file $file");
        }
        $this->_file_handle = $fh;

        $signature = fread($fh, 8);
        if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
            throw new ReaderException("File doesn't seem to be an OLE container.");
        }
        fseek($fh, 28);
        if (fread($fh, 2) != "\xFE\xFF") {
            // This shouldn't be a problem in practice
            throw new ReaderException('Only Little-Endian encoding is supported.');
        }
        // Size of blocks and short blocks in bytes
        $this->bigBlockSize = pow(2, self::_readInt2($fh));
        $this->smallBlockSize = pow(2, self::_readInt2($fh));

        // Skip UID, revision number and version number
        fseek($fh, 44);
        // Number of blocks in Big Block Allocation Table
        $bbatBlockCount = self::_readInt4($fh);

        // Root chain 1st block
        $directoryFirstBlockId = self::_readInt4($fh);

        // Skip unused bytes
        fseek($fh, 56);
        // Streams shorter than this are stored using small blocks
        $this->bigBlockThreshold = self::_readInt4($fh);
        // Block id of first sector in Short Block Allocation Table
        $sbatFirstBlockId = self::_readInt4($fh);
        // Number of blocks in Short Block Allocation Table
        $sbbatBlockCount = self::_readInt4($fh);
        // Block id of first sector in Master Block Allocation Table
        $mbatFirstBlockId = self::_readInt4($fh);
        // Number of blocks in Master Block Allocation Table
        $mbbatBlockCount = self::_readInt4($fh);
        $this->bbat = [];

        // Remaining 4 * 109 bytes of current block is beginning of Master
        // Block Allocation Table
        $mbatBlocks = [];
        for ($i = 0; $i < 109; ++$i) {
            $mbatBlocks[] = self::_readInt4($fh);
        }

        // Read rest of Master Block Allocation Table (if any is left)
        $pos = $this->_getBlockOffset($mbatFirstBlockId);
        for ($i = 0; $i < $mbbatBlockCount; ++$i) {
            fseek($fh, $pos);
            for ($j = 0; $j < $this->bigBlockSize / 4 - 1; ++$j) {
                $mbatBlocks[] = self::_readInt4($fh);
            }
            // Last block id in each block points to next block
            $pos = $this->_getBlockOffset(self::_readInt4($fh));
        }

        // Read Big Block Allocation Table according to chain specified by $mbatBlocks
        for ($i = 0; $i < $bbatBlockCount; ++$i) {
            $pos = $this->_getBlockOffset($mbatBlocks[$i]);
            fseek($fh, $pos);
            for ($j = 0; $j < $this->bigBlockSize / 4; ++$j) {
                $this->bbat[] = self::_readInt4($fh);
            }
        }

        // Read short block allocation table (SBAT)
        $this->sbat = [];
        $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
        $sbatFh = $this->getStream($sbatFirstBlockId);
        for ($blockId = 0; $blockId < $shortBlockCount; ++$blockId) {
            $this->sbat[$blockId] = self::_readInt4($sbatFh);
        }
        fclose($sbatFh);

        $this->_readPpsWks($directoryFirstBlockId);

        return true;
    }
public function read ( $ file ) { $ fh = fopen ( $ file , 'r' ) ; if ( ! $ fh ) { throw new ReaderException ( "Can't open file $file" ) ; } $ this -> _file_handle = $ fh ; $ signature = fread ( $ fh , 8 ) ; if ( "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $ signature ) { throw new ReaderException ( "File doesn't seem to be an OLE container." ) ; } fseek ( $ fh , 28 ) ; if ( fread ( $ fh , 2 ) != "\xFE\xFF" ) { // This shouldn't be a problem in practice throw new ReaderException ( 'Only Little-Endian encoding is supported.' ) ; } // Size of blocks and short blocks in bytes $ this -> bigBlockSize = pow ( 2 , self :: _readInt2 ( $ fh ) ) ; $ this -> smallBlockSize = pow ( 2 , self :: _readInt2 ( $ fh ) ) ; // Skip UID, revision number and version number fseek ( $ fh , 44 ) ; // Number of blocks in Big Block Allocation Table $ bbatBlockCount = self :: _readInt4 ( $ fh ) ; // Root chain 1st block $ directoryFirstBlockId = self :: _readInt4 ( $ fh ) ; // Skip unused bytes fseek ( $ fh , 56 ) ; // Streams shorter than this are stored using small blocks $ this -> bigBlockThreshold = self :: _readInt4 ( $ fh ) ; // Block id of first sector in Short Block Allocation Table $ sbatFirstBlockId = self :: _readInt4 ( $ fh ) ; // Number of blocks in Short Block Allocation Table $ sbbatBlockCount = self :: _readInt4 ( $ fh ) ; // Block id of first sector in Master Block Allocation Table $ mbatFirstBlockId = self :: _readInt4 ( $ fh ) ; // Number of blocks in Master Block Allocation Table $ mbbatBlockCount = self :: _readInt4 ( $ fh ) ; $ this -> bbat = [ ] ; // Remaining 4 * 109 bytes of current block is beginning of Master // Block Allocation Table $ mbatBlocks = [ ] ; for ( $ i = 0 ; $ i < 109 ; ++ $ i ) { $ mbatBlocks [ ] = self :: _readInt4 ( $ fh ) ; } // Read rest of Master Block Allocation Table (if any is left) $ pos = $ this -> _getBlockOffset ( $ mbatFirstBlockId ) ; for ( $ i = 0 ; $ i < $ mbbatBlockCount ; ++ $ i ) { fseek ( $ fh , $ pos ) ; for ( $ j = 0 ; $ j < $ this -> bigBlockSize / 4 - 1 ; ++ $ j ) { $ mbatBlocks [ ] = self :: _readInt4 ( $ fh ) ; } // Last block id in each block points to next block $ pos = $ this -> _getBlockOffset ( self :: _readInt4 ( $ fh ) ) ; } // Read Big Block Allocation Table according to chain specified by $mbatBlocks for ( $ i = 0 ; $ i < $ bbatBlockCount ; ++ $ i ) { $ pos = $ this -> _getBlockOffset ( $ mbatBlocks [ $ i ] ) ; fseek ( $ fh , $ pos ) ; for ( $ j = 0 ; $ j < $ this -> bigBlockSize / 4 ; ++ $ j ) { $ this -> bbat [ ] = self :: _readInt4 ( $ fh ) ; } } // Read short block allocation table (SBAT) $ this -> sbat = [ ] ; $ shortBlockCount = $ sbbatBlockCount * $ this -> bigBlockSize / 4 ; $ sbatFh = $ this -> getStream ( $ sbatFirstBlockId ) ; for ( $ blockId = 0 ; $ blockId < $ shortBlockCount ; ++ $ blockId ) { $ this -> sbat [ $ blockId ] = self :: _readInt4 ( $ sbatFh ) ; } fclose ( $ sbatFh ) ; $ this -> _readPpsWks ( $ directoryFirstBlockId ) ; return true ; }
Reads an OLE container from the contents of the file given.

@acces public

@param string $file

@throws ReaderException

@return bool true on success, PEAR_Error on failure
Reads an OLE container from the contents of the file given .