WP_Filesystem_FTPext::exists( string $path ): bool

Checks if a file or directory exists.


Parameters

$path string Required
Path to file or directory.

Top ↑

Return

bool Whether $path exists or not.


Top ↑

Source

File: wp-admin/includes/class-wp-filesystem-ftpext.php. View all references

public function exists( $path ) {
	/*
	 * Check for empty path. If ftp_nlist() receives an empty path,
	 * it checks the current working directory and may return true.
	 *
	 * See https://core.trac.wordpress.org/ticket/33058.
	 */
	if ( '' === $path ) {
		return false;
	}

	$list = ftp_nlist( $this->link, $path );

	if ( empty( $list ) && $this->is_dir( $path ) ) {
		return true; // File is an empty directory.
	}

	return ! empty( $list ); // Empty list = no file, so invert.
}


Top ↑

Changelog

Changelog
Version Description
6.3.0 Returns false for an empty path.
2.5.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.