-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.php
executable file
·46 lines (36 loc) · 831 Bytes
/
Storage.php
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
39
40
41
42
43
44
45
46
<?php
/**
* Created by PhpStorm.
* User: yidashi
* Date: 16/7/21
* Time: 下午5:49
*/
namespace common\components;
use creocoder\flysystem\Filesystem;
use yii\base\Component;
class Storage extends Component
{
public $baseUrl;
/**
* @var array|string|Filesystem
*/
public $fs;
public function init()
{
parent::init();
$this->baseUrl = \Yii::getAlias($this->baseUrl);
$this->fs = \Yii::createObject($this->fs);
}
public function getPath($filename)
{
return $this->fs->getAdapter()->applyPathPrefix($filename);
}
public function getUrl($filename)
{
return $this->baseUrl . '/' . $filename;
}
public function upload($target, $source)
{
return $this->fs->write($target, file_get_contents($source));
}
}