yii2: Wrong mime type detection for CSV files

I’ve used a file validator like this:

[['upload'], 'file', 'skipOnEmpty' => false, 'extensions' => 'csv'],

Even if i upload a valid CSV file, i always get the error “Only files with these extensions are allowed: csv.”.

The reason is, that in FileValidator::validateExtension() the mime type is detected as “text/plain” instead of “text/csv”. Thus FileHelper::getExtensionsByMimeType() doesn’t return csv as valid extension.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 4
  • Comments: 18 (13 by maintainers)

Most upvoted comments

You may want to turn off $checkExtensionByMimeType to have more predictable behavior when you set extensions and mimeTypes explicitly.