-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.php
103 lines (51 loc) · 1.64 KB
/
video.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
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
<?php
/**
* PHP上传视频
*/
$upfile = $_FILES['video'];
function upload_file($files, $path = "./upload",$imagesExt=['jpg','png','jpeg','gif','mp4'])
{
// 判断错误号
if (@$files['error'] == 00) {
// 判断文件类型
$ext = strtolower(pathinfo(@$files['name'],PATHINFO_EXTENSION));
if (!in_array($ext,$imagesExt)){
return "非法文件类型";
}
// 判断是否存在上传到的目录
if (!is_dir($path)){
mkdir($path,0777,true);
}
// 生成唯一的文件名
$fileName = md5(uniqid(microtime(true),true)).'.'.$ext;
// 将文件名拼接到指定的目录下
$destName = $path."/".$fileName;
// 进行文件移动
if (!move_uploaded_file($files['tmp_name'],$destName)){
return "文件上传失败!";
}
return "文件上传成功!";
} else {
// 根据错误号返回提示信息
switch (@$files['error']) {
case 1:
echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";
break;
case 2:
echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
break;
case 3:
echo "文件只有部分被上传";
break;
case 4:
echo "没有文件被上传";
break;
case 6:
case 7:
echo "系统错误";
break;
}
}
}
echo upload_file($upfile);
?>