win_is_writable

函数
win_is_writable ( $path )
参数
  • (string) $path Windows path to check for write-ability.
    Required:
返回值
  • (bool) Whether the path is writable.
相关
  • https://bugs.php.net/bug.php?id=27609
  • https://bugs.php.net/bug.php?id=30931
定义位置
相关方法
wp_is_writableis_iterablewp_iso_descrambler_get_list_tablewp_is_mobile
引入
2.8.0
弃用
-

win_is_writable: 这个函数用来检查一个文件或目录在Windows系统中是否可写。它需要一个参数–$path–它是要检查的文件或目录的路径。

解决is_writable()函数中的Windows bug

PHP在确定一个目录是否可写时与Windows的ACL有问题,这个方法通过检查打开文件的权限来解决,而不是依靠PHP来解释操作系统的ACL。

function win_is_writable( $path ) {
	if ( '/' === $path[ strlen( $path ) - 1 ] ) {
		// If it looks like a directory, check a random file within the directory.
		return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' );
	} elseif ( is_dir( $path ) ) {
		// If it's a directory (and not a file), check a random file within the directory.
		return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
	}

	// Check tmp file for read/write capabilities.
	$should_delete_tmp_file = ! file_exists( $path );

	$f = @fopen( $path, 'a' );
	if ( false === $f ) {
		return false;
	}
	fclose( $f );

	if ( $should_delete_tmp_file ) {
		unlink( $path );
	}

	return true;
}

常见问题

FAQs
查看更多 >