Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For PHP 8.1 FileHelper::getMimeType always return null for UploadedFile #19465

Open
zerg4000 opened this issue Jul 2, 2022 · 1 comment
Open

Comments

@zerg4000
Copy link

zerg4000 commented Jul 2, 2022

For PHP 8.1 FileHelper::getMimeType always return null for UploadedFile and validate return false.
Because UploadedFile dont have extension, see FileHelper::getMimeType method

if (PHP_VERSION_ID >= 80100) {
    return static::getMimeTypeByExtension($file, $magicFile);
}

and see
FileValidator::validateExtension method:

$mimeType = FileHelper::getMimeType($file->tempName, null, false);
if ($mimeType === null) {
    return false;
}

What steps will reproduce the problem?

Use rule for UploadedFile

public function rules() {
      return [
            ['image', 'image', 'extensions' => 'png, jpg, webp']
    ];

and upload png, jpg or webp file

What is the expected result?

validate true

What do you get instead?

validate false
Error: Only files with these extensions are allowed: png, jpg, webp.

Additional info

Q A
Yii version 2.0.45
PHP version 8.1.7
Operating system Alpine
@lesha724
Copy link
Contributor

lesha724 commented Jul 3, 2022

#19307, #19243 fix it. Check it in current master branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants