$file = $request->file(‘file’);
$url_path = ‘tmp’;
r
u
l
e
=
[
′
j
p
g
′
,
′
p
n
g
′
,
′
g
i
f
′
]
;
i
f
(
rule = ['jpg', 'png', 'gif']; if (
rule=[′jpg′,′png′,′gif′];if(file->isValid()) {
$clientName = $file->getClientOriginalName();
$tmpName = $file->getFileName();
$realPath = $file->getRealPath();
$entension =
f
i
l
e
−
>
g
e
t
C
l
i
e
n
t
O
r
i
g
i
n
a
l
E
x
t
e
n
s
i
o
n
(
)
;
i
f
(
!
i
n
a
r
r
a
y
(
file->getClientOriginalExtension(); if (!in_array(
file−>getClientOriginalExtension();if(!inarray(entension, $rule)) {
return ‘图片格式为jpg,png,gif’;
}
$newName = md5(date(“Y-m-d H:i:s”) . $clientName) . “.” . $entension;
$path =
f
i
l
e
−
>
m
o
v
e
(
file->move(
file−>move(url_path, $newName);
$namePath = $url_path . ‘/’ . $newName;
return $path;
}
laravel图片上传
最新推荐文章于 2024-08-23 11:25:42 发布