复制代码
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213我这里加了 封面图片 可以不理睬! 我没有存oss.
阿里的OSS 自己可以去官网下载 我这里放到 Vendor 下的.
1 # 注意这里OSS中 请设置 存储空间名称为公共的 才能直接使用这里返回的地址进行播放 不然 需要加密呗 2 use OSSCoreOssException; # 必须 3 use OSSOssClient; # 必须 4 class ClasstimeAction extends CommonAction 5 { 6 public function add_sub() 7 { 8 header('Content-type:text/html,charset:ust-8'); 9 $file = $_FILES['file']; 10 $filTtype = $file['name'];//文件名 11 $fileName = substr($filTtype,strrpos($filTtype,'.')); 12 $filetype = array('.jpg', '.jpeg', '.gif', '.bmp', '.png'); 13 $str = rand(1,99999); 14 $useName = date('Ymd').$str; 15 $picNewName = $useName.$fileName; 16 $upload_path = "../Public/Rbac/file/"; 17 if (!in_array($fileName, $filetype)) 18 { 19 $this->success("图片格式错误","__APP__/Public/index"); 20 exit; 21 } 22 if(!is_uploaded_file($file['tmp_name'])){ 23 $this->success("请使用正确途径上传图片","__APP__/Public/index"); 24 exit; 25 } 26 if(!move_uploaded_file($file['tmp_name'],$upload_path.$picNewName)){ 27 $this->success("图片存储失败 请重新上传","__APP__/Public/index"); 28 exit; 29 } 30 31 32 #视频 33 $video = $_FILES['video']; 34 $videoTtype = $video['name'];//文件名 35 $videoName = substr($videoTtype,strrpos($videoTtype,'.')); 36 $videotype = array('.mp4'); // 自定 我这随便写一个 37 $str = rand(1,99999); 38 $useName = date('Ymd').$str; 39 $videoNewName = $useName.$videoName; 40 $upload_path = "../Public/Rbac/video/"; 41 if (in_array($videoName, $videotype)) { 42 if (is_uploaded_file($video['tmp_name'])) { 43 if (move_uploaded_file($video['tmp_name'],$upload_path.$videoNewName)) { 44 45 vendor('OSS.autoload'); // 引入 oss上传类 46 $accessKeyId = "xxxxxxxxxx"; //去阿里云后台获取秘钥 47 $accessKeySecret = "xxxxxxxxxx"; //去阿里云后台获取秘钥 48 $endpoint = "xxxxxxxxxx"; //你的阿里云OSS地址 49 50 $object = date('Y-m-d').'/'.$videoTtype; //想要保存文件的名称 51 $file = $upload_path.$videoNewName; //文件路径,必须是本地的。 52 $bucket = "xxxxxxxxxx"; // 存储空间。 53 54 try{ 55 $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); 56 $getOssInfo = $ossClient->uploadFile($bucket, $object, $file); 57 if($getOssInfo['info']['http_code'] == 200){ 58 unlink($file); # 上传成功删除本地文件 59 $curl = $getOssInfo['info']['url']; 60 # 添加数据库 61 $time = $_POST['classsc'].':'.$_POST['classsc1']; 62 $data['addresspic'] = $picNewName; 63 $data['addressvideo'] = $curl; 64 $data['classtime'] = $_POST['classtime']; 65 $data['classjj'] = $_POST['classjj']; 66 $data['classsc'] = $time; 67 $data['cid'] = $_REQUEST['code']; 68 $data['type'] = $_REQUEST['testSee']; 69 $data['syrenqun'] = $_REQUEST['classshiyin']; 70 $data['status'] = 1; 71 $data['ctime'] = time(); 72 $data['user'] = $_SESSION['name']; 73 D("classtime")->add($data); 74 $this->success("操作成功"); 75 }else{ 76 $this->error("上传OSS异常"); 77 } 78 // 抛出异常 79 } catch(OssException $e) { 80 printf(__FUNCTION__ . ": FAILEDn"); 81 printf($e->getMessage() . "n"); 82 return; 83 } 84 85 }else{ 86 $this->success("视频存储失败 请重新上传","__APP__/Public/index"); 87 exit; 88 } 89 }else{ 90 $this->success("请使用正确途径上传视频","__APP__/Public/index"); 91 exit; 92 } 93 }else{ 94 $this->success("请上传正确的视频格式 支持格式(mp4)","__APP__/Public/index"); 95 exit; 96 } 97 } 98 } 99 100 101
转载于:https://www.cnblogs.com/G921123/p/10086654.html
最后
以上就是甜蜜唇膏最近收集整理的关于OSS 视频存储的全部内容,更多相关OSS内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复