ImportController.php
864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?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); 
            }
        }
    }
}