|
- <?php
-
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
- namespace common\helpers;
-
- use yii\web\UploadedFile;
-
- class Upload {
-
- public static function uploadFile($model, $champs, $filename_old = '') {
- $file = UploadedFile::getInstance($model, $champs);
- if ($file) {
- $file_name = $file->baseName . '-' . uniqid() . '.' . $file->extension;
- $file->saveAs('../../frontend/web/uploads/' . $file_name);
- $model->$champs = $file_name;
- } else {
- $model->$champs = $filename_old;
- }
-
- $model->save();
- }
-
- }
|