validate_file() - WordPress 函数参考中文文档

返回介绍

validate_file()

发布于 2017-09-11 字数2940 浏览 858 评论 0

validate_file( string $file,  array $allowed_files = '' )

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.


参数

$file

(string)
(Required)
File path.

$allowed_files

(array)
(Optional)
List of allowed files.

Default value: ”


返回值

(int) 0 means nothing is wrong, greater than 0 means something was wrong.


源代码

File: wp-includes/functions.php

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;
}

更新日志

Version 描述
1.2.0 Introduced.

相关函数

Used By

  • wp-admin/includes/ajax-actions.php:
    wp_ajax_delete_plugin()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_update_plugin()
  • wp-admin/includes/plugin.php:
    validate_plugin()
  • wp-admin/includes/file.php:
    validate_file_to_edit()
  • wp-includes/load.php:
    wp_get_active_and_valid_plugins()
  • wp-includes/template.php:
    get_single_template()
  • wp-includes/template.php:
    get_page_template()
  • wp-includes/ms-load.php:
    wp_get_active_network_plugins()
  • Show 3 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Valid file path

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

    Invalid file path

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

上一篇:validate_email()

下一篇:validate_file_to_edit()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!