bp_document_readfile_chunked( string $file, int $start, int $length )
Read file chunked.
Description
Reads file in chunks so big downloads are possible without changing PHP.INI – http://codeigniter.com/wiki/Download_helper_for_large_files/.
Parameters
- $file
-
(Required) File.
- $start
-
(Required) Byte offset/position of the beginning from which to read from the file.
- $length
-
(Required) Length of the chunk to be read from the file in bytes, 0 means full file.
Return
(bool) Success or fail
Source
File: bp-document/bp-document-filters.php
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 | function bp_document_readfile_chunked( $file , $start = 0, $length = 0 ) { if ( ! defined( 'BP_DOCUMENT_CHUNK_SIZE' ) ) { define( 'BP_DOCUMENT_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 = @ filesize ( $file ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged } $read_length = (int) BP_DOCUMENT_CHUNK_SIZE; if ( $length ) { $end = $start + $length - 1; @ fseek ( $handle , $start ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged $p = @ ftell ( $handle ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged while ( ! @ feof ( $handle ) && $p <= $end ) { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged // Don't run past the end of file. if ( $p + $read_length > $end ) { $read_length = $end - $p + 1; } echo @ fread ( $handle , $read_length ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.XSS.EscapeOutput.OutputNotEscaped, WordPress.WP.AlternativeFunctions.file_system_read_fread $p = @ ftell ( $handle ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged if ( ob_get_length() ) { ob_flush(); flush (); } } } else { while ( ! @ feof ( $handle ) ) { // @codingStandardsIgnoreLine. echo @ fread ( $handle , $read_length ); // @codingStandardsIgnoreLine. if ( ob_get_length() ) { ob_flush(); flush (); } } } return @fclose( $handle ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fclose } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.1 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.