Advertisements

validate_file

Definition:
function validate_file( $file, $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.

Parameters

  • string $file: File path.
  • array $allowed_files: List of allowed files.

Return values

returns:0 means nothing is wrong, greater than 0 means something was wrong.

Source code

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;

}

3323

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: