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

[3.x]: Model Validation for Fileuploads fails when on PHP 8.1 #13411

Closed
JensvdHeydt opened this issue Jul 10, 2023 · 3 comments
Closed

[3.x]: Model Validation for Fileuploads fails when on PHP 8.1 #13411

JensvdHeydt opened this issue Jul 10, 2023 · 3 comments
Assignees

Comments

@JensvdHeydt
Copy link

What happened?

Description

I'm using a custom controller to receive file uploads. Those uploads are validated via a YII file extension validator. Since upgrading to PHP 8.1 the model validation failed to work and resulted in an error regarding the file extension being forbidden.

I've noticed that when I add the following option 'checkExtensionByMimeType' => false, the validation works again.
This seems to be a known problem with YII. See: yiisoft/yii2#19243

Steps to reproduce

  1. Define a File Model using the following code:

class UploadForm extends Model
{
public ?UploadedFile $file;

public function rules(): array
{
    return [
      [['file'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png,jpg,jpeg,svg,pdf,doc,ppt'],
    ];
}

}

  1. Validate a model containing (for example) a file named "image.png"

Expected behavior

The validation should work when uploading a file with a valid extension.

Actual behavior

The validation fails with PHP 8.1

Craft CMS version

3.8.13

PHP version

8.1

Operating system and version

linux

Database type and version

mariadb

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

This was fixed in Yii 2.0.47, so we just created a 3.9 branch that updates Yii to 2.0.48.1 (#13444).

To get the update early, change your craftcms/cms requirement to 3.9.x-dev as 3.9.0-alpha in composer.json, and then run composer update.

@JensvdHeydt
Copy link
Author

@brandonkelly Thank you very much! I've yet to find time to review the change but I guess update Yii will do the trick, since it's a Yii problem after all.

@brandonkelly
Copy link
Member

Craft 3.9.0 was just released with Yii 2.0.48.1 🎉

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

No branches or pull requests

3 participants