forked from org-yii-china/yii2-file-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileUpload.php
54 lines (48 loc) · 1.63 KB
/
FileUpload.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
47
48
49
50
51
52
53
54
<?php
namespace common\widgets\file_upload;
use Yii;
use yii\widgets\InputWidget;
use yii\helpers\Html;
use yii\web\View;
use common\widgets\file_upload\assets\FileUploadAsset;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
class FileUpload extends InputWidget
{
public $config = [];
public $value = '';
public function init()
{
$_config = [
'serverUrl' => Url::to(['upload','action'=>'uploadimage']), //上传服务器地址
'fileName' => 'upfile', //提交的图片表单名称
'domain_url' => '', //图片域名 不填为当前域名
];
$this->config = ArrayHelper::merge($_config, $this->config);
}
public function run()
{
$this->registerClientScript();
if ($this->hasModel()) {
$inputName = Html::getInputName($this->model, $this->attribute);
$inputValue = Html::getAttributeValue($this->model, $this->attribute);
return $this->render('index',[
'config'=>$this->config,
'inputName' => $inputName,
'inputValue' => $inputValue,
]);
} else {
return $this->render('index',[
'config'=>$this->config,
'inputName' => 'file-upload',
'inputValue' => $this->value,
]);
}
}
public function registerClientScript()
{
FileUploadAsset::register($this->view);
//$script = "FormFileUpload.init();";
//$this->view->registerJs($script, View::POS_READY);
}
}