public static function uploadedFile($file, array $options = [])
    {
        $options += [
            'minSize' => null,
            'maxSize' => null,
            'types' => null,
            'optional' => false,
        ];
        if (!is_array($file) && !($file instanceof UploadedFileInterface)) {
            return false;
        }
        $error = $isUploaded = false;
        if ($file instanceof UploadedFileInterface) {
            $error = $file->getError();
            $isUploaded = true;
        }
        if (is_array($file)) {
            $keys = ['error', 'name', 'size', 'tmp_name', 'type'];
            ksort($file);
            if (array_keys($file) != $keys) {
                return false;
            }
            $error = (int)$file['error'];
            $isUploaded = is_uploaded_file($file['tmp_name']);
        }

        if (!static::uploadError($file, $options['optional'])) {
            return false;
        }
        if ($options['optional'] && $error === UPLOAD_ERR_NO_FILE) {
            return true;
        }
        if (isset($options['minSize']) && !static::fileSize($file, static::COMPARE_GREATER_OR_EQUAL, $options['minSize'])) {
            return false;
        }
        if (isset($options['maxSize']) && !static::fileSize($file, static::COMPARE_LESS_OR_EQUAL, $options['maxSize'])) {
            return false;
        }
        if (isset($options['types']) && !static::mimeType($file, $options['types'])) {
            return false;
        }

        return $isUploaded;
    }
public static function uploadedFile($file, array $options = [])
    {
        $options += [
            'minSize' => null,
            'maxSize' => null,
            'types' => null,
            'optional' => false,
        ];
        if (!is_array($file) && !($file instanceof UploadedFileInterface)) {
            return false;
        }
        $error = $isUploaded = false;
        if ($file instanceof UploadedFileInterface) {
            $error = $file->getError();
            $isUploaded = true;
        }
        if (is_array($file)) {
            $keys = ['error', 'name', 'size', 'tmp_name', 'type'];
            ksort($file);
            if (array_keys($file) != $keys) {
                return false;
            }
            $error = (int)$file['error'];
            $isUploaded = is_uploaded_file($file['tmp_name']);
        }

        if (!static::uploadError($file, $options['optional'])) {
            return false;
        }
        if ($options['optional'] && $error === UPLOAD_ERR_NO_FILE) {
            return true;
        }
        if (isset($options['minSize']) && !static::fileSize($file, static::COMPARE_GREATER_OR_EQUAL, $options['minSize'])) {
            return false;
        }
        if (isset($options['maxSize']) && !static::fileSize($file, static::COMPARE_LESS_OR_EQUAL, $options['maxSize'])) {
            return false;
        }
        if (isset($options['types']) && !static::mimeType($file, $options['types'])) {
            return false;
        }

        return $isUploaded;
    }
public static function uploadedFile ( $ file , array $ options = [ ] ) { $ options += [ 'minSize' => null , 'maxSize' => null , 'types' => null , 'optional' => false , ] ; if ( ! is_array ( $ file ) && ! ( $ file instanceof UploadedFileInterface ) ) { return false ; } $ error = $ isUploaded = false ; if ( $ file instanceof UploadedFileInterface ) { $ error = $ file -> getError ( ) ; $ isUploaded = true ; } if ( is_array ( $ file ) ) { $ keys = [ 'error' , 'name' , 'size' , 'tmp_name' , 'type' ] ; ksort ( $ file ) ; if ( array_keys ( $ file ) != $ keys ) { return false ; } $ error = ( int ) $ file [ 'error' ] ; $ isUploaded = is_uploaded_file ( $ file [ 'tmp_name' ] ) ; } if ( ! static :: uploadError ( $ file , $ options [ 'optional' ] ) ) { return false ; } if ( $ options [ 'optional' ] && $ error === UPLOAD_ERR_NO_FILE ) { return true ; } if ( isset ( $ options [ 'minSize' ] ) && ! static :: fileSize ( $ file , static :: COMPARE_GREATER_OR_EQUAL , $ options [ 'minSize' ] ) ) { return false ; } if ( isset ( $ options [ 'maxSize' ] ) && ! static :: fileSize ( $ file , static :: COMPARE_LESS_OR_EQUAL , $ options [ 'maxSize' ] ) ) { return false ; } if ( isset ( $ options [ 'types' ] ) && ! static :: mimeType ( $ file , $ options [ 'types' ] ) ) { return false ; } return $ isUploaded ; }
Validate an uploaded file.

Helps join `uploadError`, `fileSize` and `mimeType` into
one higher level validation method.

### Options

- `types` - An array of valid mime types. If empty all types
will be accepted. The `type` will not be looked at, instead
the file type will be checked with ext/finfo.
- `minSize` - The minimum file size in bytes. Defaults to not checking.
- `maxSize` - The maximum file size in bytes. Defaults to not checking.
- `optional` - Whether or not this file is optional. Defaults to false.
If true a missing file will pass the validator regardless of other constraints.

@param array|\Psr\Http\Message\UploadedFileInterface $file The uploaded file data from PHP.
@param array $options An array of options for the validation.
@return bool
Validate an uploaded file .