前端:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<
html
>
<
body
>
<
form
action
=
"/static/uploadList/upload.php"
method
=
"post"
enctype
=
"multipart/form-data"
>
<
label
for
=
"file"
>licenseImage:</
label
>
<
input
type
=
"file"
name
=
"licenseImage[]"
id
=
"file1"
/>
<
input
type
=
"file"
name
=
"licenseImage[]"
id
=
"file2"
/>
<
input
type
=
"file"
name
=
"licenseImage[]"
id
=
"file3"
/>
<
input
type
=
"file"
name
=
"licenseImage[]"
id
=
"file4"
/>
<
br
/>
<
input
type
=
"submit"
name
=
"submit"
value
=
"Submit"
/>
</
form
>
</
body
>
</
html
>
|
后端:
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
|
<?php
$ret
=
array
();
foreach
(
$_FILES
[
"licenseImage"
][
"error"
]
as
$key
=>
$error
) {
if
(
$error
> 0) {
var_dump(
$_FILES
[
'licenseImage'
]);
var_dump(
"图片上传失败!!!"
);
exit
;
$ret
[
'status'
] = 2;
$ret
[
'dataInfo'
] =
"图片上传失败!!!"
;
return
$ret
;
}
else
{
// 临时文件
$pathFile
= @
$_FILES
[
'licenseImage'
] [
'tmp_name'
][
$key
];
// 文件名
$fileName
=
$_FILES
[
"licenseImage"
] [
"name"
][
$key
];
//文件大小
$fileSize
=
$_FILES
[
"licenseImage"
][
"size"
][
$key
];
// 文件类型
// 获取上传文件的扩展名
$extend
=
strrpos
(
$fileName
,
'.'
);
//strrchr ( $fileName, '.' );
// 文件内容:file_get_contents($pathFile)
// 文件大小:$_FILES["file"]["size"]
// 文件在服务器中的暂存位置:$_FILES["file"]["tmp_name"]
// 判断文件类型是否是image
# 当前支持的类型列表
$type_list
=
array
(
'1'
=>
'jpg'
,
'2'
=>
'png'
,
'3'
=>
'jpeg'
,
);
/*if (in_array($extend, array_values($type_list))) {
$ret ['status'] = 3;
$ret ['dataInfo'] = "上传文件的类型错误!!!";
return $ret;
}
#判断上传图片的大小
if( ($fileSize/1024 ) > 2048 ){
$ret ['status'] = 4;
$ret ['dataInfo'] = "上传已经大于2M!!!";
return $ret;
}*/
}
//IF_END
// 无后缀的文件名
$fname
=
basename
(
$fileName
,
$extend
);
$time
=
date
(
"y-m-d-H-i-s"
);
// 去当前上传的时间
// 保存的文件名
$fNewname
=
$fname
.
"_"
.
$time
.
"."
.
$extend
;
$result
= move_uploaded_file (
$pathFile
,
$fNewname
);
}
|
版权声明:原创作品,如需转载,请注明出处。否则将追究法律责任
本文转自 梦朝思夕 51CTO博客,原文链接:http://blog.51cto.com/qiangmzsx/1545755