文章目录
本文最后更新于 2022-10-29,已超过 365 天未更新,内容可能已失效。

validate_file( string $file, string[] $allowed_files = array() )

根据允许的一组规则验证文件名和路径。
Validates a file name and path against an allowed set of rules.


说明(Description)

返回值1表示文件路径包含目录遍历。返回值2表示文件路径包含Windows驱动器路径。返回值3表示文件不在允许的文件列表中。


参数(Parameters)

参数类型说明
$file(string)文件路径。
$allowed_files(string[])允许的文件数组。

源码(Source)

/**
 * File validates against allowed set of defined rules.
 *
 * A return value of '1' means that the $file contains either '..' or './'. A
 * return value of '2' means that the $file contains ':' after the first
 * character. A return value of '3' means that the file is not in the allowed
 * files list.
 *
 * @since 1.2.0
 *
 * @param string $file File path.
 * @param array  $allowed_files List of allowed files.
 * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
 */
function validate_file( $file, $allowed_files = '' ) {
    if ( false !== strpos( $file, '..' ) )
        return 1;
 
    if ( false !== strpos( $file, './' ) )
        return 1;
 
    if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
        return 3;
 
    if (':' == substr( $file, 1, 1 ) )
        return 2;
 
    return 0;
}
更新版本源码位置使用被使用
1.2.0wp-includes/functions.php514

CC 许可协议
署名-非商业性使用-相同方式共享 4.0 国际 了解协议
文章链接:https://zptheme.com/5474.html
本文作者:子佩·来源:子佩工作室

除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。

相关推荐

企业级 WordPress 资源商城主题:深空主题重磅发布-DSPro主题
299

企业级原创企业级 WordPress 资源商城主题:深空主题重磅发布-DSPro主题

深空 DSPro 是基于 WordPress 开发的企业级资...

登录后即可发表评论

社交账号登录

全部评论 (0)