docx-uploading fails

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']],

    ]);

    ?>



Uuups,sorry,my fault.

Everything is gonna all right. Files have been uploaded, but in another alias folder. I noticed this fact looking for my gitTool.

This code changed alias folder





         foreach ($model->attachement as $uploaded_file) {

                $model->dateiname = $uploaded_file->baseName . "." . $uploaded_file->extension;

                if ($uploaded_file->extension == "pdf") {

                    $folder_write = Yii::getAlias('@documents/');

                    $bez = "Anhang für:";

                } else {

                    $folder_write = Yii::getAlias('@pictures/'); // this line caused my error

                    $bez = "Bild für:";

                }

            }



So,this thread can be closed