<?php
header(
"content-type:text/html;charset=utf-8"
);
function
changeFile(
$oldfile
){
$newfile
=
$_FILES
[
'file'
][
'name'
];
$fileclass
=
substr
(
strrchr
(
$newfile
,
'.'
), 1);
$type
=
array
(
"jpg"
,
"gif"
,
"bmp"
,
"jpeg"
,
"png"
);
if
(in_array(
strtolower
(
$fileclass
),
$type
)){
if
(
file_exists
(
$oldfile
)){
unlink(
$oldfile
);
}
if
(
is_uploaded_file
(
$_FILES
[
'file'
][
'tmp_name'
])){
if
(move_uploaded_file(
$_FILES
[
'file'
][
'tmp_name'
],
$oldfile
)){
echo
"<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src="
$oldfile
"></center>"
;
}
}
else
{
echo
"<center>上传失败,文件大于2M,请重新上传!</center>"
;
}
}
else
{
$text
= implode(
","
,
$type
);
echo
"<center>您只能上传以下类型文件:"
,
$text
,
"</center><br>"
;
}
}
changeFile(
"./files/1.png"
);