wp_filesize

函式
wp_filesize ( $path )
引數
  • (string) $path Path to the file.
    Required:
返回值
  • (int) The size of the file in bytes, or 0 in the event of an error.
定義位置
相關方法
wp_filesystemwp_getimagesizewp_insert_sitewp_timezonewp_filter_kses
引入
6.0.0
棄用
-

wp_filesize: 這個函式用來將檔案大小的位元組格式化為更可讀的格式,如千位元組、兆位元組等。它接收以位元組為單位的檔案大小作為引數,並返回格式化後的大小。

帶有過濾器的PHP檔案大小的封裝器,並將結果鑄成整數。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_filesize( $path ) {
/**
* Filters the result of wp_filesize before the PHP function is run.
*
* @since 6.0.0
*
* @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
* @param string $path Path to the file.
*/
$size = apply_filters( 'pre_wp_filesize', null, $path );
if ( is_int( $size ) ) {
return $size;
}
$size = file_exists( $path ) ? (int) filesize( $path ) : 0;
/**
* Filters the size of the file.
*
* @since 6.0.0
*
* @param int $size The result of PHP filesize on the file.
* @param string $path Path to the file.
*/
return (int) apply_filters( 'wp_filesize', $size, $path );
}
function wp_filesize( $path ) { /** * Filters the result of wp_filesize before the PHP function is run. * * @since 6.0.0 * * @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call. * @param string $path Path to the file. */ $size = apply_filters( 'pre_wp_filesize', null, $path ); if ( is_int( $size ) ) { return $size; } $size = file_exists( $path ) ? (int) filesize( $path ) : 0; /** * Filters the size of the file. * * @since 6.0.0 * * @param int $size The result of PHP filesize on the file. * @param string $path Path to the file. */ return (int) apply_filters( 'wp_filesize', $size, $path ); }
function wp_filesize( $path ) {
	/**
	 * Filters the result of wp_filesize before the PHP function is run.
	 *
	 * @since 6.0.0
	 *
	 * @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
	 * @param string   $path Path to the file.
	 */
	$size = apply_filters( 'pre_wp_filesize', null, $path );

	if ( is_int( $size ) ) {
		return $size;
	}

	$size = file_exists( $path ) ? (int) filesize( $path ) : 0;

	/**
	 * Filters the size of the file.
	 *
	 * @since 6.0.0
	 *
	 * @param int    $size The result of PHP filesize on the file.
	 * @param string $path Path to the file.
	 */
	return (int) apply_filters( 'wp_filesize', $size, $path );
}

常見問題

FAQs
檢視更多 >