lib/ezfile/classes/ezfile.php
public static function downloadContent( $file, $startOffset = 0, $length = false )
    {
        if ( !file_exists( $file ) )
        {
            eZDebug::writeError( "'$file' does not exist", __METHOD__ );
            return false;
        }
        if ( ( $fp = fopen( $file, 'rb' ) ) === false )
        {
            eZDebug::writeError( "An error occured opening '$file' for reading", __METHOD__ );
            return false;
        }

        $fileSize = filesize( $file );

        // an offset has been given: move the pointer to that offset if it seems valid
        if ( $startOffset !== false && $startOffset <= $fileSize && fseek( $fp, $startOffset ) === -1 )
        {
            eZDebug::writeError( "Error while setting offset on '{$file}'", __METHOD__ );
            return false;
        }

        $transferred = $startOffset;
        $packetSize = self::READ_PACKET_SIZE;
        $endOffset = ( $length === false ) ? $fileSize - 1 : $length + $startOffset - 1;

        while ( !feof( $fp ) && $transferred < $endOffset + 1 )
        {
            if ( $transferred + $packetSize > $endOffset + 1 )
            {
                $packetSize = $endOffset + 1 - $transferred;
            }
            echo fread( $fp, $packetSize );
            $transferred += $packetSize;
        }
        fclose( $fp );

        return true;
    }
public static function downloadContent( $file, $startOffset = 0, $length = false )
    {
        if ( !file_exists( $file ) )
        {
            eZDebug::writeError( "'$file' does not exist", __METHOD__ );
            return false;
        }
        if ( ( $fp = fopen( $file, 'rb' ) ) === false )
        {
            eZDebug::writeError( "An error occured opening '$file' for reading", __METHOD__ );
            return false;
        }

        $fileSize = filesize( $file );

        // an offset has been given: move the pointer to that offset if it seems valid
        if ( $startOffset !== false && $startOffset <= $fileSize && fseek( $fp, $startOffset ) === -1 )
        {
            eZDebug::writeError( "Error while setting offset on '{$file}'", __METHOD__ );
            return false;
        }

        $transferred = $startOffset;
        $packetSize = self::READ_PACKET_SIZE;
        $endOffset = ( $length === false ) ? $fileSize - 1 : $length + $startOffset - 1;

        while ( !feof( $fp ) && $transferred < $endOffset + 1 )
        {
            if ( $transferred + $packetSize > $endOffset + 1 )
            {
                $packetSize = $endOffset + 1 - $transferred;
            }
            echo fread( $fp, $packetSize );
            $transferred += $packetSize;
        }
        fclose( $fp );

        return true;
    }
public static function downloadContent ( $ file , $ startOffset = 0 , $ length = false ) { if ( ! file_exists ( $ file ) ) { eZDebug :: writeError ( "'$file' does not exist" , __METHOD__ ) ; return false ; } if ( ( $ fp = fopen ( $ file , 'rb' ) ) === false ) { eZDebug :: writeError ( "An error occured opening '$file' for reading" , __METHOD__ ) ; return false ; } $ fileSize = filesize ( $ file ) ; // an offset has been given: move the pointer to that offset if it seems valid if ( $ startOffset !== false && $ startOffset <= $ fileSize && fseek ( $ fp , $ startOffset ) === - 1 ) { eZDebug :: writeError ( "Error while setting offset on '{$file}'" , __METHOD__ ) ; return false ; } $ transferred = $ startOffset ; $ packetSize = self :: READ_PACKET_SIZE ; $ endOffset = ( $ length === false ) ? $ fileSize - 1 : $ length + $ startOffset - 1 ; while ( ! feof ( $ fp ) && $ transferred < $ endOffset + 1 ) { if ( $ transferred + $ packetSize > $ endOffset + 1 ) { $ packetSize = $ endOffset + 1 - $ transferred ; } echo fread ( $ fp , $ packetSize ) ; $ transferred += $ packetSize ; } fclose ( $ fp ) ; return true ; }
Handles the data part of a file transfer to the client

@see download()

@param string $file Path to the local file
@param int $startOffset Offset to start transfer from, in bytes
@param int $length Data size to transfer
Handles the data part of a file transfer to the client