WC_Download_Handler::readfile_chunked
Read file chunked.
Reads file in chunks so big downloads are possible without changing PHP.INI - http://codeigniter.com/wiki/Download_helper_for_large_files/.
Method of the class: WC_Download_Handler{}
No Hooks.
Returns
bool. Success or fail
Usage
$result = WC_Download_Handler::readfile_chunked( $file, $start, $length );
- $file(string) (required)
- File.
- $start(int)
- Byte offset/position of the beginning from which to read from the file.
- $length(int)
- Length of the chunk to be read from the file in bytes, 0 means full file.
WC_Download_Handler::readfile_chunked() WC Download Handler::readfile chunked code WC 11.1.2
public static function readfile_chunked( $file, $start = 0, $length = 0 ) {
// 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 false;
}
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 );
}