Completed
Pull Request — master (#44)
by
unknown
04:35
created

DownloadAction::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: execut
5
 * Date: 5/19/17
6
 * Time: 11:59 AM
7
 */
8
9
namespace pastuhov\ymlcatalog\actions;
10
11
12
use yii\base\Action;
13
14
class DownloadAction extends Action
15
{
16
    public $fileName = null;
17
    public $publicPath = null;
18
19
    public function run() {
20
        $file = \yii::getAlias($this->publicPath) . '/' . $this->fileName;
21
        $response = \Yii::$app->getResponse();
22
        $response->setDownloadHeaders($this->fileName, mime_content_type($file));
23
24
        $response->sendContentAsFile(file_get_contents($file), $this->fileName);
25
26
        return $response;
27
    }
28
}