<?php
if ($_FILES) {
// 获取文件后缀
$temp = explode(".", $_FILES[‘img‘]["name"]);
$extension = end($temp);
//判断文件类型
if (
$_FILES[‘img‘][‘type‘] == "image/png" || $_FILES[‘img‘][‘type‘] == "image/jpg"
|| $_FILES[‘img‘][‘type‘] == "image/jpeg" || $_FILES[‘img‘][‘type‘] == "image/gif"
&& $_FILES[‘img‘][‘size‘] <= 204800
) {
$uname = ‘./uploads‘ . time() . mt_rand(100, 900) . ‘.‘ . $extension;
move_uploaded_file($_FILES[‘img‘][‘tmp_name‘], $uname);
echo $uname;
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 上传文件必须写enctype="multipart/form-data"属性 -->
<form action="" method="post" enctype="multipart/form-data" name="uname">
<input type="file" name="img" id="">
<input type="submit" value="提交">
</form>
</body>
</html>