WC_Download_Handler::readfile_chunked_with_result
Read a file in chunks and report when a failure follows partial output.
Method of the class: WC_Download_Handler{}
No Hooks.
Returns
string. One of the READ_RESULT_* constants.
Usage
$result = WC_Download_Handler::readfile_chunked_with_result( $file, $start, $length );
- $file(string) (required)
- File.
- $start(int) (required)
- Byte offset/position of the beginning from which to read from the file.
- $length(int) (required)
- Length of the chunk to be read from the file in bytes, 0 means full file.
WC_Download_Handler::readfile_chunked_with_result() WC Download Handler::readfile chunked with result code WC 11.2.2
private static function readfile_chunked_with_result( $file, $start, $length ) {
// Define before attempting to open the file: the constant has always been defined even
// when the open fails, and external code may rely on that side effect.
if ( ! defined( 'WC_CHUNK_SIZE' ) ) {
define( 'WC_CHUNK_SIZE', 1024 * 1024 );
}
$handle = @fopen( $file, 'r' ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
if ( false === $handle ) {
return self::READ_RESULT_FAILURE_BEFORE_OUTPUT;
}
if ( ! $length ) {
$length = (int) @filesize( $file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Remote paths make filesize error; false is handled by the cast (0 means read until EOF).
}
return self::readfile_from_handle( $handle, $start, $length );
}