UploadImage.php
2.48 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* 图片相关功能区块视图
* @author wuxiao
* @date 2016-8-12
*/
namespace backend\widgets;
use Yii;
use yii\base\Widget;
use yii\web\View;
class UploadImage extends Widget
{
const appName = 'Image';
/**
* 实例化自身
* @return \YHGImage\Upload\Client
*/
public static function self()
{
return new self();
}
/**
* 单个头像上传功能区块,整个页面只能有一个此区块
* @param string $name 文件表单name, 即在form中的表单名
* @param string $value 文件表单默认值
*/
public function logo($name, $value = '')
{
$view = $this->getView();
$view->registerCssFile('/js/webuploader/webuploader.css');
$view->registerCssFile('/js/webuploader/upload.css');
$view->registerJsFile('/js/webuploader/webuploader.min.js');
$view->registerJsFile('/js/uploadlogo.js');
return $this->render('upload/logo',[
'name'=>$name,
'value'=>$value,
]);
}
/**
* 单个图片上传功能区块,页面可以有多个此区块
* @param string $name 文件表单name, 即在form中的表单名
* @param string $value 文件表单默认值
*/
public function single($name, $value = '')
{
$id = sprintf('%u',crc32(uniqid(true)));
$view = $this->getView();
$view->registerCssFile('/js/webuploader/webuploader.css');
$view->registerCssFile('/js/webuploader/upload.css');
$pre = <<<EOT
<script>
var uploaders = [], uidx = 0;
</script>
EOT;
return $pre . $this->render('upload/single',[
'id'=>$id,
'name'=>$name,
'value'=>$value,
]);
}
/**
* 多图上传功能区块
* @param string $name 文件表单name, 即在form中的表单名
* @param array $value 文件表单多图默认值
*/
public static function mutil($name,$values = array())
{
$appConfig = Registry::get('appConfig');
$url = '/static';
$appName = self::appName;
$values = is_array($values) ? $values : array($values);
$view = new ViewSimple(APPLICATION_PATH."/application/modules/{$appName}/views/tpl");
return $view
->assign('name',$name)
->assign('values',$values)
->assign('url',$url)
->assign('appName',$appName)
->render('mutil.phtml');
}
}