ImportController.php 864 Bytes
<?php

namespace backend\controllers;

use Yii;
use backend\models\Import;
use yii\web\UploadedFile;

class ImportController extends \yii\web\Controller
{
    public function actionIndex()
    {
        $model = new Import();
        return $this->render('index', [
            'model' => $model
        ]);
    }

    public function actionUpload()
    {
        $model = new Import(); 
    
        if ($model->load(Yii::$app->request->post())) 
        {
            $model->file = UploadedFile::getInstances($model, 'file');
 
            // Копируем файл в директорию
            $path = $_SERVER['DOCUMENT_ROOT'].'/import/';
 
            foreach ($model->file as $file) 
            { 
                //var_dump(substr ($path.$file->name, 0, -10)); die; 
                Import::importFile ($file); 
            }
        }
    }

}