Hi all,
I’ve created a model to upload CSV files, thus:
<?php
namespace app\models;
use yii\base\Model;
use yii\web\UploadedFile;
/**
* UploadForm is the model behind the upload form.
*/
class UploadFile extends Model
{
/**
* @var UploadedFile file attribute
*/
public $file;
/**
* Check that the uploaded file is a CVS file
* @return array the validation rules.
*/
public function rules()
{
return [
[['file'], 'file', 'skipOnEmpty' => false, 'extensions' => 'csv, txt',],
];
}
}
?>
I then created a controller and view to allow a CSV file to be uploaded. If I specify an extensions rule and then try to upload a CSV file, I get the following error message:
yet the file I uploaded definitely has .csv extension.
Is this a bug in the Yii2 FileValidator class, or am I doing something wrong here?
I inserted the following logging code into the FileValidator::validateExtension method:
Yii::info("In validateExtension, extension = $extension, valid extensions = " . var_dump($this->extensions));
and when I looked at the log file, the message logged was as follows: