33 public static function fileSize( $filename, $precision = 2 )
35 static $units = array(
47 if ( is_file( $filename ) ) {
48 if ( !realpath( $filename ) ) {
49 $filename = $_SERVER[
'DOCUMENT_ROOT'] . $filename;
51 $bytes = filesize( $filename );
54 $e = floor( log( $bytes ) / log( 1024 ) );
55 return sprintf(
'%.' . $precision .
'f ' . $units[$e], ( $bytes / pow( 1024, floor( $e ) ) ) );
91 function _rglob( $path, $match =
'', &$result = array() ) {
92 $files = glob( trailingslashit( $path ) .
'*', GLOB_MARK );
93 if (
false !== $files ) {
94 foreach ( $files as $file ) {
95 if ( is_dir( $file ) ) {
96 $continue = apply_filters(
'wpdk_rglob_find_dir',
true, $file );
98 _rglob( $file, $match, $result );
101 elseif ( !empty( $match ) ) {
102 $continue = apply_filters(
'wpdk_rglob_find_file',
true, $file );
103 if (
false == $continue ) {
106 $regexp_result = array();
107 $error = preg_match( $match, $file, $regexp_result );
108 if ( 0 !== $error ||
false !== $error ) {
109 $regexp_result = apply_filters(
'wpdk_rglob_matched', $regexp_result, $file, $match );
110 if ( !empty( $regexp_result ) ) {
111 $result[] = $regexp_result[0];
125 return _rglob( $path, $match, $result );
138 public static function ext( $filename )
140 return end( explode(
'.', strtolower( basename( $filename ) ) ) );
156 $parts = explode(
'.', strtolower( basename( $filename ) ) );
159 if ( empty( $parts ) ) {
163 elseif ( count( $parts ) > 2 ) {
164 unset( $parts[count( $parts ) - 1] );
165 return implode(
',', $parts );
169 return current( $parts );