首先确保模板的form有enctype=“multipart/form-data”
//引入封装类并实例化:
include_once(ROOT_PATH . ‘/include/cls_image.php’);
i
m
a
g
e
=
n
e
w
c
l
s
i
m
a
g
e
(
image = new cls_image(
image=newclsimage(_CFG[‘bgcolor’]);
//获取前端选择的图片信息:
f
r
e
e
p
h
o
t
o
=
i
s
s
e
t
(
freephoto = isset(
freephoto=isset(_FILES[‘freephoto’]) ?
F
I
L
E
S
[
′
f
r
e
e
p
h
o
t
o
′
]
:
′
′
;
/
/
判
断
格
式
:
i
f
(
i
s
s
e
t
(
_FILES['freephoto'] : ''; //判断格式: if (isset(
FILES[′freephoto′]:′′;//判断格式:if(isset(freephoto[‘error’])){
// 最大上传文件大小
$php_maxsize = ini_get(‘upload_max_filesize’);
h
t
m
m
a
x
s
i
z
e
=
′
2
M
′
;
i
f
(
htm_maxsize = '2M'; if (
htmmaxsize=′2M′;if(freephoto[‘error’] == 0)
{
if (!
i
m
a
g
e
−
>
c
h
e
c
k
i
m
g
t
y
p
e
(
image->check_img_type(
image−>checkimgtype(freephoto[‘type’]))
{
show_message(KaTeX parse error: Expected 'EOF', got '}' at position 39: …g']); }̲ } …freephoto[‘error’] == 1)
{
show_message(sprintf($_LANG[‘goods_img_too_big’], KaTeX parse error: Expected 'EOF', got '}' at position 24: …ize)); }̲ elseif…freephoto[‘error’] == 2)
{
show_message(sprintf($_LANG[‘goods_img_too_big’], KaTeX parse error: Expected 'EOF', got '}' at position 24: …ize)); }̲ } //完成…other[‘freephoto’] 的值最终是一个图片路径,可直接存入数据库
if ($freephoto[‘name’] != “”){
$other[‘freephoto’] =
i
m
a
g
e
−
>
u
p
l
o
a
d
i
m
a
g
e
(
image->upload_image(
image−>uploadimage(freephoto,‘freephoto’);
}