modules/media/Media.php
private function insertMedia($file)
    {
        /**
         * @var \yii\web\UploadedFile $file
         */

        $result = ['success' => false, 'message' => 'File could not be saved.'];

        if ($file->size > Yii::$app->params['maxUploadSize']) {
            $result['message'] = 'Max upload size limit reached';
        }

        $uploadTime = date("Y-m-W");
        $media = new MediaModel();

        $media->filename = KatoBase::sanitizeFile($file->baseName) . '-' . KatoBase::genRandomString(4) . '.' . $file->extension;
        $media->mimeType = $file->type;
        $media->byteSize = $file->size;
        $media->extension = $file->extension;
        $media->source = basename(\Yii::$app->params['uploadPath']) . '/' . $uploadTime . '/' . $media->filename;


        if (!is_file($media->source)) {
            //If saved upload the file
            $uploadPath = \Yii::$app->params['uploadPath'] . $uploadTime;
            if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);

            if ($file->saveAs($uploadPath . '/' . $media->filename)) {
                //Save to media table
                if ($media->save(false)) {
                    $result['success'] = true;
                    $result['message'] = 'Upload Success';
                    $result['data'] = $media;
                } else {
                    $result['message'] = "Database record could not be saved.";
                }
            } else {
                $result['message'] = "File could not be saved.";
            }
        } else {
            $result['message'] = "File already exists.";
        }

        return $result;
    }
private function insertMedia($file)
    {
        /**
         * @var \yii\web\UploadedFile $file
         */

        $result = ['success' => false, 'message' => 'File could not be saved.'];

        if ($file->size > Yii::$app->params['maxUploadSize']) {
            $result['message'] = 'Max upload size limit reached';
        }

        $uploadTime = date("Y-m-W");
        $media = new MediaModel();

        $media->filename = KatoBase::sanitizeFile($file->baseName) . '-' . KatoBase::genRandomString(4) . '.' . $file->extension;
        $media->mimeType = $file->type;
        $media->byteSize = $file->size;
        $media->extension = $file->extension;
        $media->source = basename(\Yii::$app->params['uploadPath']) . '/' . $uploadTime . '/' . $media->filename;


        if (!is_file($media->source)) {
            //If saved upload the file
            $uploadPath = \Yii::$app->params['uploadPath'] . $uploadTime;
            if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);

            if ($file->saveAs($uploadPath . '/' . $media->filename)) {
                //Save to media table
                if ($media->save(false)) {
                    $result['success'] = true;
                    $result['message'] = 'Upload Success';
                    $result['data'] = $media;
                } else {
                    $result['message'] = "Database record could not be saved.";
                }
            } else {
                $result['message'] = "File could not be saved.";
            }
        } else {
            $result['message'] = "File already exists.";
        }

        return $result;
    }
Upload to file and insert into media table
@param $file
@return array