Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
validate_file() - 根据允许的规则集验证文件名和路径 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / validate_file()

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

根据允许的规则集验证文件名和路径


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "4a75aeb879471a176496188a632a5785" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "22b750ced8b78e13c56086f67756b5d0" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

file


描述

返回值1表示文件路径包含目录遍历。

返回值2表示文件路径包含Windows驱动器路径。

返回值3表示文件不在允许的文件列表中。


参数

$file

(string) (必填) 文件路径

$allowed_files

(string[]) (可选) 允许的文件数组

默认值: array()


返回

(int) 0 表示没有任何问题,大于 0 表示有问题。



源码

查看源码 官方文档


更新日志

版本描述
1.2.0开始引入

使用示例

  • 示例1

    有效文件路径

    $path = 'uploads/2012/12/my_image.jpg';
    return validate_file( $path ); // Returns 0 (valid path).
    

    文件路径无效

    $path = '../../wp-content/uploads/2012/12/my_image.jpg';
    return validate_file( $path ); // Returns 1 (invalid path).