README.txt
3.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Yii extensions:
http://www.yiiframework.com/extension/lcswfupload/
Author:
luochong <luochong1987@gmail.com>
#######################################################################
中文说明
SWFUpload Yii文件上传 整合 swfupload
flash文件上传
支持多文件同时上传
显示文件上传进度条
Requirements
Yii 1.1 or above
Usage
SWFUpload 图片上传
第一步:在控制器类里面载入SWFUploadAction
public function actions() {
return array(
'upload'=>array(
'class'=>'application.extensions.swfupload.SWFUploadAction',
'filepath'=>'/var/www/yourpath/yourfilename.EXT', //注意这里是绝对路径,.EXT是文件后缀名替代符号
)
);
}
说明:
你必须要有这个upload action的权限,可以在accessRules函数中添加upload action 的访问权限
filepath 文件的完整上传路径 包括文件名 如: C:/file/logo.EXT 后缀名是用户上传的文件决定所以在这里只需要用 .EXT 替代
SWFUploadAction支持两个事件 onBeforeUpload 和 onAfterUpload
第二步:在视图中调用widget
<?php
$this->widget('application.extensions.swfupload.SWFUpload',array('callbackJS'=>'swfupload_callback'));
?>
说明:
callbackJS 是图片上传后执行的js函数 函数定义格式如下:
第一参数是文件名字name,
第二参数是文件路径path,
第三参数是oldname是文件的原始名字,
javascript代码如下:
function swfupload_callback(name,path,oldname)
{
$("#Sponsor_logo").val(name);
$("#thumbnails_1").html("<img src='"+path+"/"+name+"?"+(new Date()).getTime()+"' />");
}
#########################################################################################
English description
SWFUpload is a small JavaScript/Flash library to get the best of both worlds. It features the great upload capabilities of Flash and the accessibility and ease of HTML/CSS now combined with the power of Yii framework.
Requirements
Yii 1.1 or above
Installation
Extract the release file under protected/extensions
Directory structure like this
--extensions
----swfupload
------assets
------views
------SWFUpload.php
------SWFUploadAction.php
Usage
See the following code example:
On controller
public function accessRules()
{
return array(
array('allow',
'actions'=>array('upload'),
'users'=>array('*'),
),
......
);
}
public function actions() {
return array(
'upload'=>array(
'class'=>'application.extensions.swfupload.SWFUploadAction',
'filepath'=>'/var/www/yourpath/yourfilename.EXT', // 'EXT' will be replaced by file extension
'onAfterUpload'=>array($this,'saveFile'),
)
);
}
public function saveFile($event)
{
//$event->sender['uploadedFile'] is CUploadedFile
//$event->sender['uploadedFile']->name; the original name of the file being uploaded
// $event->sender['name'] yourfilename.EXT
// do something ......
}
On Views
<?php
$this->widget('application.extensions.swfupload.SWFUpload',array(
'callbackJS'=>'swfupload_callback',
)
);
?>
<input type="text" name="image_name" id="image_name" />
<script>
function swfupload_callback(name,path,oldname)
{
$("#image_name").val(name);
$("#thumbnails_1").html("<img src='"+path+"/"+name+"?"+(new Date()).getTime()+"' />");
}
</script>