html文件的名称:upload.html
<!DOCTYPE HTML>
<html>
<head>
<title></title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
php文件名称:upload.php
<?php
$file=$_FILES['file'];
$str = $file['name'];
$extName = substr($str,strrpos($str,"."));
$fileName = uniqid();
$uploadName = $fileName.$extName;
if(move_uploaded_file($file['tmp_name'],$uploadName)){
echo '上传成功';
}else{
echo '上传失败';
}