# jetformbuilder/3.6.6/includes/classes/resources/file-tools.php

JetFormBuilder — Dynamic Blocks Form Builder, version 3.6.6. 87 lines.

- Page: https://pluginprobe.com/plugins/jetformbuilder/3.6.6/code/includes/classes/resources/file-tools.php
- Raw: https://pluginprobe.com/plugins/jetformbuilder/3.6.6/raw/includes/classes/resources/file-tools.php
- Modified: 2026-03-20T07:01:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/jetformbuilder/3.6.6/code/includes/classes/resources/file-tools.php#L10-L20`.

```php
<?php


namespace Jet_Form_Builder\Classes\Resources;

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

class File_Tools {

	public static function get_uploaded( File $file, $preset ) {
		if ( $preset instanceof Uploaded_File && self::is_same_file( $file, $preset ) ) {
			return $preset;
		}

		if ( ! is_array( $preset ) ) {
			return false;
		}

		/** @var Uploaded_File $uploaded */
		foreach ( $preset as $uploaded ) {
			if ( self::is_same_file( $file, $uploaded ) ) {
				return $uploaded;
			}
		}

		return false;
	}

	protected static function is_same_file( File $file, Uploaded_File $uploaded_file ): bool {
		$preset_path = $uploaded_file->get_attachment_file();

		if ( ! $preset_path ) {
			return false;
		}

		$info = pathinfo( $preset_path );

		return $file->get_name() === ( $info['basename'] ?? '' );
	}

	public static function is_same_ext( string $file_name, string $need_ext ): bool {
		$ext = self::get_file_ext( $file_name );

		if ( 0 === strpos( $need_ext, '.' ) ) {
			$need_ext = substr( $need_ext, 1, strlen( $need_ext ) - 1 );
		}

		return $ext === $need_ext;
	}

	public static function get_file_ext( string $file_name ): string {
		$file_parts = explode( '.', $file_name );

		return end( $file_parts );
	}

	/**
	 * @param string|int $file_data
	 *
	 * @return Uploaded_File|false
	 */
	public static function create_uploaded_file( $file_data ) {
		if ( is_numeric( $file_data ) ) {
			$uploaded = new Uploaded_File();

			return $uploaded->set_attachment_id( $file_data );
		}

		if ( ! empty( $file_data['id'] ) && is_numeric( $file_data['id'] ) ) {
			return self::create_uploaded_file( $file_data['id'] );
		}

		// phpcs:ignore WordPress.WP.AlternativeFunctions
		if ( ! is_string( $file_data ) || false === parse_url( $file_data ) ) {
			return false;
		}

		$attachment_id = attachment_url_to_postid( $file_data );

		return $attachment_id ? self::create_uploaded_file( $attachment_id ) : false;
	}

}

```
