Hi guys,
I am totally confused,
following method will just upload pdf or jpg-files in my alias folder. All othe filetypes,which expressly are allowed to get uploaded won’t be uploaded,although var_dump shows file as it should be.Method will send true to Controller,but it actually will upload only pdf-files. Any ideas,why upload fails for other filetypes but pdf and jpg?
public function upload() {
$x = 0;
$session = Yii::$app->session;
$session->open();
if ($this->validate()) {
foreach ($this->attachement as $uploaded_file) {
$uploaded_file->saveAs(Yii::getAlias('@uploading') . '/' . $uploaded_file->baseName . '.' . $uploaded_file->extension);
$x++;
}
if ($x > 0) {
$session['go_in'] = true;
return true;
}
}
$session['go_in'] = false;
return false;
}
var_dump($this->attachement);
will show this:
E:\xampp\htdocs\yii2_perswitch\frontend\modules\dateianhang\models\base\Dateianhang.php:102:
array (size=1)
0 =>
object(yii\web\UploadedFile)[225]
public 'name' => string '12_Joinabfragen.docx' (length=20)
public 'tempName' => string 'E:\xampp\tmp\php7D53.tmp' (length=24)
public 'type' => string 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' (length=71)
public 'size' => int 81472
public 'error' => int 0
Here is rule in model
[['attachement'], 'file', 'skipOnEmpty' => false, 'maxSize' => 5*1024000, 'tooBig' => 'Maximal erlaubte Dateigröße:1 MByte', 'maxFiles' => 3],
and here is formular:
$form->field($model, 'attachement[]')->widget(FileInput::classname(), [
'options' => ['multiple' => true],
'pluginOptions' => ['allowedFileExtensions' => ['jpg', 'bmp', 'png', 'docx', 'xlsx', 'csv', 'pptx', 'pdf', 'txt']],
]);
?>