Title: WP_Filesystem_Base::getnumchmodfromh
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_Filesystem_Base::getnumchmodfromh( string $mode ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#wp--skip-link--target)

Converts *nix-style file permissions to an octal number.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#description)󠁿

Converts ‘-rw-r–r–‘ to 0644 From “info at rvgate dot nl”‘s comment on the PHP documentation
for chmod()

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#parameters)󠁿

 `$mode`stringrequired

string The *nix-style file permissions.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#return)󠁿

 string Octal representation of permissions.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#source)󠁿

    ```php
    public function getnumchmodfromh( $mode ) {
    	$realmode = '';
    	$legal    = array( '', 'w', 'r', 'x', '-' );
    	$attarray = preg_split( '//', $mode );

    	for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
    		$key = array_search( $attarray[ $i ], $legal, true );

    		if ( $key ) {
    			$realmode .= $legal[ $key ];
    		}
    	}

    	$mode  = str_pad( $realmode, 10, '-', STR_PAD_LEFT );
    	$trans = array(
    		'-' => '0',
    		'r' => '4',
    		'w' => '2',
    		'x' => '1',
    	);
    	$mode  = strtr( $mode, $trans );

    	$newmode  = $mode[0];
    	$newmode .= $mode[1] + $mode[2] + $mode[3];
    	$newmode .= $mode[4] + $mode[5] + $mode[6];
    	$newmode .= $mode[7] + $mode[8] + $mode[9];

    	return $newmode;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-base.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-wp-filesystem-base.php#L420)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-filesystem-base.php#L420-L448)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getnumchmodfromh/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_filesystem_base%2Fgetnumchmodfromh%2F)
before being able to contribute a note or feedback.