validate_file
File validates against allowed set of defined rules.
Description
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.
Returns (int)
0 means nothing is wrong, greater than 0 means something was wrong.
Parameters (2)
- 0. $file (string)
- File path.
- 1. $allowed_files — Optional. (string) =>
''
- List of allowed files.
Usage
if ( !function_exists( 'validate_file' ) ) { require_once ABSPATH . WPINC . '/functions.php'; } // File path. $file = ''; // List of allowed files. $allowed_files = ''; // NOTICE! Understand what this does before running. $result = validate_file($file, $allowed_files);
Defined (1)
The function is defined in the following location(s).
- /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;
- }