WC_Download_Handler - readfile_chunked refactor
This commit is contained in:
parent
1ffa095ef1
commit
3aaa397361
|
@ -321,29 +321,18 @@ class WC_Download_Handler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* readfile_chunked
|
* readfile_chunked
|
||||||
|
*
|
||||||
* Reads file in chunks so big downloads are possible without changing PHP.INI - http://codeigniter.com/wiki/Download_helper_for_large_files/
|
* Reads file in chunks so big downloads are possible without changing PHP.INI - http://codeigniter.com/wiki/Download_helper_for_large_files/
|
||||||
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @param bool $retbytes return bytes of file
|
* @return bool Success or fail
|
||||||
* @return bool|int
|
|
||||||
* @todo Meaning of the return value? Last return is status of fclose?
|
|
||||||
*/
|
*/
|
||||||
public static function readfile_chunked( $file, $retbytes = true ) {
|
public static function readfile_chunked( $file ) {
|
||||||
$chunksize = 1 * ( 1024 * 1024 );
|
$chunksize = 1 * ( 1024 * 1024 );
|
||||||
$buffer = '';
|
|
||||||
$cnt = 0;
|
|
||||||
|
|
||||||
if ( file_exists( $file ) ) {
|
if ( file_exists( $file ) || ( version_compare( PHP_VERSION, '5.4.0', '<' ) && ini_get( 'safe_mode' ) ) ) {
|
||||||
$handle = fopen( $file, 'r' );
|
if ( ( $handle = @fopen( $file, 'r' ) ) === false ) {
|
||||||
if ( $handle === FALSE ) {
|
return false;
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
} elseif ( version_compare( PHP_VERSION, '5.4.0', '<' ) && ini_get( 'safe_mode' ) ) {
|
|
||||||
$handle = @fopen( $file, 'r' );
|
|
||||||
if ( $handle === FALSE ) {
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( ! feof( $handle ) ) {
|
while ( ! feof( $handle ) ) {
|
||||||
|
@ -353,19 +342,12 @@ class WC_Download_Handler {
|
||||||
ob_flush();
|
ob_flush();
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $retbytes ) {
|
|
||||||
$cnt += strlen( $buffer );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = fclose( $handle );
|
return fclose( $handle );
|
||||||
|
|
||||||
if ( $retbytes && $status ) {
|
|
||||||
return $cnt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $status;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ function woocommerce_create_page( $slug, $option = '', $page_title = '', $page_c
|
||||||
*/
|
*/
|
||||||
function woocommerce_readfile_chunked( $file, $retbytes = true ) {
|
function woocommerce_readfile_chunked( $file, $retbytes = true ) {
|
||||||
_deprecated_function( 'woocommerce_readfile_chunked', '2.1', 'WC_Download_Handler::readfile_chunked()' );
|
_deprecated_function( 'woocommerce_readfile_chunked', '2.1', 'WC_Download_Handler::readfile_chunked()' );
|
||||||
return WC_Download_Handler::readfile_chunked( $file, $retbytes );
|
return WC_Download_Handler::readfile_chunked( $file );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue