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
|
||||
*
|
||||
* 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 bool $retbytes return bytes of file
|
||||
* @return bool|int
|
||||
* @todo Meaning of the return value? Last return is status of fclose?
|
||||
* @return bool Success or fail
|
||||
*/
|
||||
public static function readfile_chunked( $file, $retbytes = true ) {
|
||||
public static function readfile_chunked( $file ) {
|
||||
$chunksize = 1 * ( 1024 * 1024 );
|
||||
$buffer = '';
|
||||
$cnt = 0;
|
||||
|
||||
if ( file_exists( $file ) ) {
|
||||
$handle = fopen( $file, 'r' );
|
||||
if ( $handle === 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;
|
||||
if ( file_exists( $file ) || ( version_compare( PHP_VERSION, '5.4.0', '<' ) && ini_get( 'safe_mode' ) ) ) {
|
||||
if ( ( $handle = @fopen( $file, 'r' ) ) === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( ! feof( $handle ) ) {
|
||||
|
@ -353,19 +342,12 @@ class WC_Download_Handler {
|
|||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
|
||||
if ( $retbytes ) {
|
||||
$cnt += strlen( $buffer );
|
||||
}
|
||||
}
|
||||
|
||||
$status = fclose( $handle );
|
||||
|
||||
if ( $retbytes && $status ) {
|
||||
return $cnt;
|
||||
return fclose( $handle );
|
||||
}
|
||||
|
||||
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 ) {
|
||||
_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